Back to blog
LinuxMay 3, 202611 min read

Linux screen Command for Beginners

A simple guide to the Linux screen command: what it solves, why it matters on remote servers, and how to start, detach, reattach, and manage sessions with practical examples.

Linux screen Command for Beginners

If you work on a Linux server long enough, this will happen:

  • You start a long command.
  • Your SSH connection drops.
  • The terminal closes.
  • You reconnect and wonder if your process is still running.

That exact problem is why the screen command exists.

screen lets you create a terminal session that keeps running even if your current connection disappears. You can leave it, come back later, and continue where you stopped.

This guide keeps the idea simple. No jargon first. Just what screen is, what problem it solves, and how to use it with examples you will actually need.

What is the Linux screen command?

screen is a terminal multiplexer.

That sounds more complex than it is.

In simple words, it lets you open a terminal session that lives independently from the terminal window or SSH connection you used to start it.

So instead of this:

  • you connect to a server
  • you run a command
  • your connection closes
  • your work stops or becomes hard to recover

You get this:

  • you connect to a server
  • you start a screen session
  • you run your command inside it
  • you detach from the session
  • the command keeps running
  • you reconnect later and attach back to the same session

That is the core idea.

What problem does screen solve?

screen is useful when you need your terminal work to survive beyond your current shell session.

The most common cases are:

  • running a long script on a remote server
  • starting a deployment and checking it later
  • watching logs without losing your place
  • editing or debugging on a machine where your network may disconnect
  • keeping multiple terminal sessions organized in one place

Without screen, many commands depend on the current terminal staying open.

With screen, the session keeps running in the background after you detach.

That makes it especially useful over SSH.

Installing screen

Many Linux systems already have it. If not, install it with your package manager.

Ubuntu or Debian

sudo apt update
sudo apt install screen

Fedora

sudo dnf install screen

CentOS or RHEL

sudo yum install screen

To confirm it is installed:

screen --version

The most important workflow

If you only remember one screen workflow, remember this one:

  1. Start a named session.
  2. Run your command inside it.
  3. Detach from the session.
  4. Reattach later.

That covers most real use.

Start a new screen session

You can start screen with no name:

screen

But in practice, named sessions are better because they are easier to find later.

Use:

screen -S deploy

This creates a session named deploy.

After you run it, you are inside the screen session. It looks like a normal terminal, and that is the point. From here, run commands as usual.

Example:

screen -S backup
rsync -av ./data user@backup-server:/srv/backups

If the transfer takes a long time, you do not need to keep the connection open the whole time.

Detach from a screen session

To leave the session without stopping it, press:

Ctrl+a then d

This is the key combination beginners need most.

  • Ctrl+a tells screen that a command is coming.
  • d means detach.

After that, you go back to your normal shell and the screen session keeps running in the background.

You will usually see a message similar to this:

[detached from 12345.deploy]

List existing screen sessions

To see what sessions exist, run:

screen -ls

Example output:

There are screens on:
    12345.deploy    (Detached)
    12510.logs      (Detached)
2 Sockets in /run/screen/S-user.

This tells you:

  • the session ID
  • the session name
  • whether it is detached or attached

Reattach to a session

To come back to a detached session, use:

screen -r deploy

If you want to use the full session ID instead, that also works:

screen -r 12345.deploy

Now you are back inside the same session, with the same shell state and whatever command output was already there.

Simple example: keep a long-running script alive

Imagine you need to run a data import that takes 40 minutes.

Without screen, losing your SSH connection can interrupt your work or at least make it harder to track.

With screen:

ssh user@server
screen -S import
node scripts/import-customers.js

Then detach:

Ctrl+a then d

Later:

ssh user@server
screen -r import

You return to the same running session.

Simple example: watch logs on a remote server

This is another very common use case.

screen -S logs
tail -f /var/log/nginx/access.log

Detach when you want:

Ctrl+a then d

Reattach later:

screen -r logs

This is useful when you want a log watcher to stay available without keeping your SSH window permanently active.

End a screen session

There are two normal ways to end a session.

Method 1: exit the shell inside screen

If you are inside the session, just run:

exit

If that shell was the last thing running in the session, the screen session will close.

Method 2: kill it from outside

If needed, you can stop a session from another shell:

screen -S deploy -X quit

Use that carefully. It closes the session.

Useful beginner commands

Here are the commands worth memorizing first:

CommandWhat it does
screen -S nameStart a new named session
screen -lsList sessions
screen -r nameReattach to a session
exitClose the current shell in the session
screen -S name -X quitKill a session from outside
Ctrl+a then dDetach from the session

That small set is enough for most beginners.

Creating multiple windows inside one session

screen can do more than keep one shell alive. You can also open multiple windows inside the same session.

The most useful shortcuts are:

ShortcutWhat it does
Ctrl+a then cCreate a new window
Ctrl+a then nGo to the next window
Ctrl+a then pGo to the previous window
Ctrl+a then "Show a list of windows

Example workflow:

  • one window for application logs
  • one window for a database shell
  • one window for deployment commands

That way, one screen session can hold a small working environment.

Scrolling and copy mode

Sometimes you need to scroll up and inspect older output.

Inside screen, use:

Ctrl+a then Esc

That opens copy mode. From there, you can move with the arrow keys and inspect previous output.

To leave copy mode, press:

Esc

If scrolling feels awkward at first, that is normal. screen is powerful, but some navigation takes a little time to get used to.

A practical remote-server workflow

Here is a realistic example you can reuse:

Start the session

ssh user@my-server
screen -S release

Run deployment steps

git pull
npm install
npm run build
pm2 restart api

Detach safely

Ctrl+a then d

Check again later

ssh user@my-server
screen -r release

This is simple, but it solves a very real operational problem.

Common mistakes

These are the issues new users hit most often:

1. Forgetting to name sessions

If you create many unnamed sessions, screen -ls becomes harder to read.

Prefer:

screen -S logs
screen -S deploy
screen -S backup

2. Closing the terminal instead of detaching

If you want to keep the session available, do not just close the window and hope for the best. Get into the habit of detaching with:

Ctrl+a then d

3. Forgetting the Ctrl+a prefix

Most screen shortcuts begin with Ctrl+a.

Think of it as the command prefix for the session.

4. Reattaching to the wrong session

When in doubt, run:

screen -ls

Then attach using the exact session name or ID.

screen vs a normal terminal

The simplest difference is this:

  • A normal terminal session usually ends when the terminal or SSH connection ends.
  • A screen session can continue running after you detach.

That is why screen is still useful even though it looks old and simple.

screen vs tmux

You will often hear about tmux as well.

Both tools solve a similar problem: persistent terminal sessions and multiple windows.

For this article, the important point is not which tool is better.

The important point is that screen is often already available, easy to learn at a basic level, and more than enough for simple remote-server work.

If your only goal is to keep a process alive and reconnect later, screen does that very well.

Final takeaway

The Linux screen command solves a very practical problem: it keeps your terminal work alive when your current connection goes away.

That makes it useful for SSH sessions, deployments, log monitoring, long-running scripts, and any task you do not want tied to one fragile terminal window.

You do not need to learn every shortcut at once.

Start with four things:

  • create a named session
  • run your command inside it
  • detach with Ctrl+a then d
  • reattach with screen -r

Once that feels natural, the rest of screen becomes much easier to learn.