How to Use GNU Screen on Ubuntu 26.04 LTS
Install GNU Screen on Ubuntu 26.04 LTS and use it to keep commands running after you disconnect: sessions, windows, splits, scrollback and .screenrc.
GNU Screen keeps your shell sessions running on the server after your SSH connection drops, and lets you work in several terminal windows over a single connection. This guide covers installing and using Screen on Ubuntu 26.04 LTS, which packages Screen 4.9.1. Ubuntu 24.04 LTS and Debian 13 ship the same 4.9.1 series, so every command and key binding below works there unchanged.
Install Screen
Many Ubuntu server images already include Screen. Check first:
screen -vIf the command is not found, install the package from the Ubuntu archive:
sudo apt update
sudo apt install screenStart, detach and reattach a session
Start a session with a name, so you can find it again later:
screen -S deployYou land in a normal shell, but it now runs inside Screen. Every Screen command starts with the prefix Ctrl+A, followed by one more key. To leave the session running in the background, press Ctrl+A and then D. Screen prints a line such as [detached from 5747.deploy] and returns you to your original shell. You can now log out; anything you started inside the session keeps running.
List the sessions that belong to your user:
screen -lsReattach by name (or by the numeric ID shown in the list):
screen -r deployIf your connection dropped without detaching, the session is still marked as attached and screen -r refuses to take it. Detach it from the dead terminal and reattach in one step:
screen -d -r deployTo view the same session from two terminals at once, for example to share it with a colleague logged in as the same user, use screen -x deploy.
Run a command inside a session
Pass a command to start it directly in a new session. The session ends when the command exits:
screen -S backup rsync -a /var/www/ /mnt/backup/www/For scripts and long jobs you do not need to watch, start the session already detached with -dm:
screen -dmS backup rsync -a /var/www/ /mnt/backup/www/Check on it later with screen -r backup.
Work with windows and split regions
One session can hold many windows, each with its own shell. These are the bindings you will use most:
| Keys | Action |
|---|---|
Ctrl+A C | Create a new window |
Ctrl+A N / P | Next / previous window |
Ctrl+A 0–9 | Jump to a window by number |
Ctrl+A " | Choose a window from a list |
Ctrl+A Shift+A | Rename the current window |
Ctrl+A Shift+S | Split the display horizontally |
Ctrl+A | | Split the display vertically |
Ctrl+A Tab | Move to the next region |
Ctrl+A Shift+X | Close the current region (the window keeps running) |
Ctrl+A K | Kill the current window |
Ctrl+A ? | Show all key bindings |
A new region created by a split is empty. Move into it with Ctrl+A Tab, then create a window with Ctrl+A C or switch to an existing one. To send a literal Ctrl+A to the program inside Screen (for example to jump to the start of the line in Bash), press Ctrl+A and then A.
Scroll back and save output
Your terminal's own scrollbar does not see what happened inside Screen. Enter copy mode with Ctrl+A [, move with the arrow keys or Ctrl+B / Ctrl+F for a page up or down, and press Esc to leave.
To record everything a window prints, press Ctrl+A Shift+H. Screen writes the output to screenlog.N in the directory where the session was started, where N is the window number. Press the same keys again to stop logging.
Set defaults in ~/.screenrc
Screen reads ~/.screenrc when a session starts. A small file removes the most common annoyances:
# Skip the copyright page on startup
startup_message off
# Keep 10,000 lines of history per window (the default is 100)
defscrollback 10000
# Show the host name and window list on the last line
hardstatus alwayslastline "%H | %-w%n %t%+w"The settings apply to sessions started after you save the file; running sessions keep their old values.
End a session
A window closes when its shell exits, so type exit (or press Ctrl+D) in each window. When the last window closes, Screen prints [screen is terminating] and the session is gone. To close every window at once from inside, press Ctrl+A \ and confirm with y.
You can also end a session from outside without attaching to it:
screen -S deploy -X quitIf screen -ls lists a session as dead, for example after a crash, remove the leftover socket:
screen -wipeFrequently asked questions
Do Screen sessions survive a reboot?
No. A session is a set of running processes, and a reboot ends them. Screen protects you from lost connections and closed terminals, not from the server restarting. For work that must come back after a reboot, use a systemd service instead.
Why does screen -r say there is no screen to be resumed?
Sessions belong to the user who created them. If you started the session as deploy and are now logged in as root, or the other way round, screen -ls will not show it. Switch to the right user first. If the list shows the session as attached, use screen -d -r.
Should I use Screen or tmux?
Both solve the same problem and both are in the Ubuntu archive. Screen is often already installed and is enough for keeping a job alive and reattaching to it. tmux has more flexible pane handling and scripting. If you only need detach and reattach, the choice comes down to which key bindings you prefer.
Can I change the Ctrl+A prefix?
Yes. Add an escape line to ~/.screenrc, for example escape ^Bb to use Ctrl+B as the prefix and Ctrl+B B to send a literal Ctrl+B.