GNU Screen is a terminal multiplexer: one SSH connection, many shells — and, more importantly, shells that keep running after the connection is gone. If you have ever started a long rsync, a database migration or a kernel build over SSH and then watched the Wi-Fi drop, you already know why it exists. The job dies with the terminal unless something owns the terminal on the server side. Screen does.
This guide covers installing Screen on current distributions, the few key bindings worth memorizing, named sessions, detaching and reattaching, logging a session, a minimal .screenrc, and the troubleshooting cases that generate most support tickets ("my session disappeared", "cannot open your terminal"). It also says plainly when you should use tmux instead.
When to use Screen (and when tmux)
Screen and tmux solve the same problem. Pick Screen when it is already installed on the servers you manage, when you need to share a session with a colleague over screen -x, or when you have muscle memory for it. Pick tmux for new setups: it is in the base repositories of every major distribution, has saner defaults for splits and scrolling, and is actively developed. Everything in this guide has a one-line tmux equivalent; the concepts transfer.
Either way, the workflow is the same: start a session, run your work inside it, detach, log out, come back later, reattach.
Install Screen
Check first — many images already ship it:
screen --version
# Screen version 4.09.01 (GNU) 20-Aug-23
Debian / Ubuntu
sudo apt update
sudo apt install -y screen
RHEL, AlmaLinux, Rocky Linux, CentOS Stream
Red Hat dropped Screen from the base repositories in RHEL 8. It lives in EPEL, so enable that first:
sudo dnf install -y epel-release
sudo dnf install -y screen
On RHEL proper (not the rebuilds), enable the CodeReady Builder repo before EPEL as the EPEL documentation describes. Fedora ships Screen in its main repository: sudo dnf install screen.
Alpine
sudo apk add screen
Arch Linux
sudo pacman -S screen
Start a session
screen
You are now inside a Screen window running your login shell. It looks identical to before — the difference is that the shell is now a child of the Screen server process, not of your SSH session.
Every Screen command is prefixed with Ctrl+a (press and release), followed by a key. Ctrl+a ? shows the full binding list.
Named sessions
Unnamed sessions are addressed by PID, which nobody remembers. Name them:
screen -S migration
Names make screen -ls readable and let you reattach with screen -r migration.
Run a command directly in a detached session
For unattended jobs you don't even need to attach:
screen -dmS backup bash -c 'rsync -a /srv/data/ backup:/srv/data/ ; echo done >> /var/log/backup.log'
-d -m starts the session detached; -S names it. The command runs inside; you reattach only if you want to watch. Note that when the command exits, the window closes and the session ends — wrap it in a shell with a trailing exec bash if you want the session to survive for inspection.
The key bindings you actually need
| Binding | Action |
|---|---|
Ctrl+a c |
Create a new window |
Ctrl+a " |
List windows and pick one |
Ctrl+a n / Ctrl+a p |
Next / previous window |
Ctrl+a 0–9 |
Jump to window N |
Ctrl+a A |
Rename the current window |
Ctrl+a d |
Detach — leave everything running |
Ctrl+a [ |
Enter copy/scrollback mode (arrow keys / PgUp to scroll, Esc to leave) |
Ctrl+a H |
Toggle logging of the current window to screenlog.N |
Ctrl+a S / `Ctrl+a |
` |
Ctrl+a Tab |
Move focus to the next split region |
Ctrl+a Q |
Close all regions except the current one |
Ctrl+a X |
Close the current region (the window keeps running) |
Ctrl+a k |
Kill the current window (asks for confirmation) |
The two that matter on day one are Ctrl+a d (detach) and Ctrl+a [ (scroll back — the mouse wheel will not scroll inside Screen by default).
Detach, log out, reattach
Detach with Ctrl+a d. You will see [detached from 12345.migration] and be back in your plain SSH shell. Log out, close the laptop, come back tomorrow.
List what is still running:
screen -ls
# There is a screen on:
# 12345.migration (Detached)
# 1 Socket in /run/screen/S-deploy.
Reattach:
screen -r migration # by name
screen -r 12345 # by PID
screen -r # if there is exactly one session
If the session shows (Attached) because your previous SSH connection died without detaching cleanly, force it over:
screen -d -r migration
-d -r detaches the stale attachment first, then attaches you. This is the single most common "my session is stuck" fix.
Share a session with a colleague
Two people can attach to the same session and both see and type:
screen -x migration
Both users must be the same Unix user (or you must configure multiuser mode and ACLs with Ctrl+a :multiuser on and :acladd otheruser). For ad-hoc pairing on an incident, logging in as the same deploy user and using -x is the pragmatic route.
Log a session
To keep a transcript of everything that scrolls past — useful for change records and for pasting into a post-mortem — turn logging on inside the window:
Ctrl+a H
Screen writes to screenlog.0 (window number) in the directory where you started it. Toggle again to stop. To log from the start, launch with screen -L -S name, or set logfile /var/log/screen/%S-%n.log in .screenrc so the files land somewhere sensible.
A minimal .screenrc
Screen's defaults date from the 1990s. Four lines fix most complaints:
# ~/.screenrc
startup_message off # skip the licence splash
defscrollback 10000 # scrollback lines per window (default 100)
hardstatus alwayslastline # a status bar at the bottom...
hardstatus string '%{= kG}[%H] %{= kw}%-w%{= kY}%n %t%{-}%+w %=%{= kc}%d.%m %c'
term screen-256color # colours in vim/htop inside Screen
Reload a changed .screenrc with Ctrl+a :source ~/.screenrc or start a new session.
Troubleshooting
There is no screen to be resumed— nothing is running under this user, or the session belongs to another user (Screen sockets are per user in/run/screen/S-<user>). Check withscreen -ls, and make sure you are the same user who started it —sudo screen -lsdoes not show your own sessions.Cannot open your terminal '/dev/pts/0' - please check.— you ransuorsudo -ito another user and then started Screen. The pseudo-terminal still belongs to the original user. Eithersudo -u user script /dev/null -c screenor fix ownership withscript /dev/nullbefore runningscreen, or simply SSH in directly as that user.- Session listed as
(Dead ???)— the Screen server process died (reboot, OOM kill). The job is gone. Remove the stale socket withscreen -wipe. - Sessions vanish after reboot — expected. Screen is a process, not a service. For work that must survive reboots use a systemd unit or a cron
@rebootentry, not a multiplexer. - Mouse wheel doesn't scroll — use
Ctrl+a [and the keyboard, or addtermcapinfo xterm* ti@:te@to.screenrcso the terminal's own scrollback works for the current window. screen: command not foundon AlmaLinux/Rocky — EPEL is not enabled; see the install section.- Detached session is consuming CPU you didn't expect — the job inside is still running, which is the point. Reattach and check, or
screen -S name -X quitto terminate the whole session.
Summary
- Install:
apt install screen,dnf install epel-release screen,apk add screen. - Start named:
screen -S name; unattended:screen -dmS name command. - Detach
Ctrl+a d, listscreen -ls, reattachscreen -r name, forcescreen -d -r name. - Scroll with
Ctrl+a [, log withCtrl+a H. - For new servers, consider
tmux; for a job that must survive reboots, use systemd or cron instead of either.
Related Resources
- How to check running processes on Ubuntu Server — find the job your detached session is still running
- How to set a Linux cron job to reboot a server — includes what
@rebootdoes, the right tool for work that must survive restarts - Linux server monitoring — get alerted when a long-running job pushes CPU, memory or disk past a threshold while you are detached