Linux screen Command: Install, Detach, Reattach and Key Bindings (Cheat Sheet)

How to install GNU screen on Ubuntu, Debian, Rocky and RHEL, start named sessions, detach and reattach after an SSH drop, fix "There is no screen to be resumed", scroll back, log output and kill sessions. Tested on screen 4.9.1.

Share
Linux screen command keeping terminal sessions running on a server after SSH disconnect

Originally published in February 2020. Reviewed and updated in December 2026, tested on screen 4.9.1 (Ubuntu 24.04).

GNU screen keeps your terminal sessions alive on the server. You start a long job inside screen, your SSH connection drops or you close the laptop, and the job keeps running. Later you log in again and reattach right where you left off.

The three commands you'll use 90% of the time:

screen -S backup     # start a session named "backup"
# press Ctrl+a, then d to detach
screen -r backup     # reattach later

Everything below I tested on Ubuntu 24.04 with screen 4.9.1, including the error messages.

Install screen

Ubuntu and Debian:

sudo apt update
sudo apt install screen

Rocky Linux, AlmaLinux, RHEL 8, 9 and 10:

screen isn't in the base repositories anymore. Red Hat deprecated it in RHEL 7.6 and dropped it from RHEL 8, recommending tmux instead. It's still packaged in EPEL, so on Rocky or Alma 9 install it from there, as Rocky forum users confirm:

sudo dnf install epel-release
sudo dnf install screen

On RHEL itself, add EPEL with the epel-release-latest-9.noarch.rpm (or -10) package from the Fedora project. More on that in my EPEL install guide.

Without EPEL, dnf install screen fails with No match for argument: screen. That's the most common reason people think screen "doesn't exist" on Rocky.

On EL10, some users got Directory '/run/screen' must have mode 777. right after installing from EPEL. In the AlmaLinux forum thread, sudo dnf reinstall screen fixed it.

CentOS 7: yum install screen works from the base repo. CentOS 7 itself is end of life, though.

Check the version:

screen -v
Screen version 4.09.01 (GNU) 20-Aug-23

Ubuntu 24.04 and Debian ship 4.9.1. EPEL 10 and Fedora have 5.0.1, a security fix release from May 2025. The commands in this guide work the same on both.

Start a named session

screen -S backup

You get a new shell that looks exactly like the old one. Run whatever takes long: a backup, a big rsync, a database import.

Always name sessions with -S. Without a name, screen -ls shows only something like 234.pts-0.server, and with three of those you won't remember which is which.

To start a session that runs a command in the background without attaching to it:

screen -dmS backup bash -c 'rsync -a /data/ /mnt/backup/'

-d -m starts it detached. Handy in scripts and cron jobs.

Detach and reattach

Detach: press Ctrl+a, release, then press d. You're back in your normal shell, and the session keeps running.

List sessions:

screen -ls
There are screens on:
    234.web (12/01/26 11:26:32) (Detached)
    232.backup  (12/01/26 11:26:32) (Detached)
2 Sockets in /run/screen/S-root.
screen -ls output listing two detached screen sessions

Reattach by name or by the number in front:

screen -r backup
screen -r 232

If several sessions exist and you run plain screen -r, screen doesn't guess:

There are several suitable screens on:
    234.web (12/01/26 11:26:32) (Detached)
    232.backup  (12/01/26 11:26:32) (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

Just add the name.

"There is no screen to be resumed"

This message has three different causes. I got each of them in testing:

1. The session is still marked as attached. This is the classic one after an SSH connection drops. The old connection hasn't timed out yet, so screen thinks someone is still attached:

There is a screen on:
    309.web (12/01/26 11:26:50) (Attached)
There is no screen to be resumed matching web.

Fix: detach the old connection and attach here in one step:

screen -d -r web

Or attach a second time without detaching the first (both see the same window):

screen -x web

2. The name is wrong:

There is no screen to be resumed matching nope.

Check the exact name with screen -ls.

3. There are no sessions at all, for example after a reboot, or because the job finished and the shell exited:

No Sockets found in /run/screen/S-root.

Also check the user. Sessions belong to the user who started them. A session started as root is invisible to screen -ls run as your normal user, and the other way around.

Key bindings cheat sheet

Every screen shortcut starts with Ctrl+a, then a second key.

Keys What it does
Ctrl+a d Detach
Ctrl+a c Create a new window
Ctrl+a n / p Next / previous window
Ctrl+a 0–9 Go to window number
Ctrl+a " List windows and pick one
Ctrl+a A Rename the current window
Ctrl+a k Kill the current window
Ctrl+a S / | Split horizontally / vertically
Ctrl+a Tab Move to the next split region
Ctrl+a Esc Copy mode: scroll back with arrows or PgUp, Esc to leave
Ctrl+a ? Show all key bindings
Ctrl+a a Send a literal Ctrl+a to the program (e.g. to jump to line start in bash)

A window is like a tab inside one session. One session with several windows is often tidier than several sessions.

Scroll back

The mouse wheel usually doesn't scroll inside screen. Use copy mode: Ctrl+a, then Esc, then the arrow keys or PgUp. Press Esc again to leave.

The default scrollback is short. Make it longer for all new sessions:

echo 'defscrollback 10000' >> ~/.screenrc

Log a session to a file

screen -S build -L -Logfile ~/build.log

Everything printed in the session goes into ~/build.log. In my test, the log file appeared a few seconds after the output, because screen writes it in batches. Don't panic if it's empty for a moment.

To save just what's on the screen right now from outside the session:

screen -S build -X hardcopy ~/build-now.txt

Send a command into a running session

screen -S web -X stuff 'systemctl status nginx\n'

stuff types the text into the session as if you'd typed it yourself. The \n presses Enter. It's useful for poking a long-running session from a script or cron job.

Kill a session

From inside: exit the shell in every window (exit or Ctrl+d), or press Ctrl+a then k in each window.

From outside:

screen -S backup -X quit

To see it in motion, this short video shows the basics: starting screen, opening windows, detaching and reattaching.

screen or tmux?

Both keep sessions alive after you disconnect. My take: on a server where screen is already installed and you only need detach and reattach, screen is fine. For daily work with splits, scripting and a nicer status bar, tmux is the better tool, and on RHEL-family systems it's the one in the base repos. See my tmux tutorial and cheat sheet if you want to switch.

FAQ

How do I detach from screen without stopping the program?

Press Ctrl+a, then d. The program keeps running. Reattach later with screen -r name.

How do I reattach to a screen session after SSH disconnects?

Run screen -ls to find it, then screen -d -r name. The -d detaches the dead old connection first, which avoids "There is no screen to be resumed".

Why is screen not found on Rocky Linux or RHEL 9?

Red Hat removed screen from the base repositories in RHEL 8. Install EPEL (sudo dnf install epel-release), then sudo dnf install screen, or use tmux, which is in the base repos.

How do I scroll up in screen?

Ctrl+a, then Esc enters copy mode. Scroll with the arrow keys or PgUp, leave with Esc. Raise the limit with defscrollback 10000 in ~/.screenrc.

How do I kill all screen sessions?

Quit them one by one with screen -S name -X quit. pkill screen also works, but it kills every program running inside the sessions without warning.