How to Use Linux Screen

Have you ever started a long task on a remote machine, only to lose your connection and see your SSH session end, taking all your progress with it? GNU Screen is a terminal multiplexer that solves exactly this. It keeps your sessions running even after you disconnect, so you can resume exactly where you left off.
This guide explains how to install Screen, manage sessions and windows, detach and reattach, use scrollback mode, and customize Screen with a configuration file.
Install Linux Screen
The screen package is pre-installed on most Linux distributions. To check whether it is available, run:
screen --versionScreen version 4.09.01 (GNU) 20-Aug-23Ubuntu 26.04 and Debian 13 ship Screen 4.9.1, while Fedora 43 and newer ship Screen 5.0, so the version string on your system may look different.
If screen is not installed on your system, install it using your distribution’s package manager.
Install Linux Screen on Ubuntu, Debian, and Derivatives
sudo apt update && sudo apt install screenInstall Linux Screen on Fedora, RHEL, and Derivatives
sudo dnf install screenOn RHEL, Rocky Linux, and AlmaLinux, Screen is not in the base repositories. Enable the EPEL repository first, then run the same command.
Starting a Screen Session
To start a new Screen session, type the following in your terminal:
screenThis opens a Screen session, creates a new window, and starts a shell in it. To see all available key bindings, press Ctrl+a ? from within the session.
Starting a Named Session
Named sessions are useful when you run multiple screen sessions at the same time. To create a named session, run:
screen -S session_nameIt is always a good idea to choose a descriptive session name that reflects the task running in it. This makes it easier to identify and manage multiple sessions later.
Starting a Detached Session Running a Command
To start a session that runs a command in the background and stays detached from the start, use -dmS:
screen -dmS backup rsync -av /home /backupThis is useful over SSH when you want to launch a long-running task and disconnect immediately, without having to attach and detach by hand. While the command is running, the session shows up in screen -ls and you can attach with screen -r backup. The session ends when rsync finishes.
Working with Screen Windows
When you start a new Screen session, it creates a single window with a shell in it. You can open additional windows inside the same session at any time.
To create a new window, press Ctrl+a c. Screen assigns the first available number to the new window, starting from 0. The Ctrl+a 0 to Ctrl+a 9 shortcuts jump directly to the first ten windows; for windows with higher numbers, pick them from the window list.
Here are the most common key bindings for managing windows:
Ctrl+ac- Create a new window (with shell).Ctrl+a"- List all windows.Ctrl+a0- Switch to window 0 (by number).Ctrl+aA- Rename the current window.Ctrl+ak- Kill the current window.Ctrl+aS- Split the current region horizontally into two regions.Ctrl+a|- Split the current region vertically into two regions.Ctrl+aTab- Switch the input focus to the next region.Ctrl+aCtrl+a- Toggle between the current and previous window.Ctrl+aQ- Close all regions except the current one.Ctrl+aX- Close the current region.
Detach from a Screen Session
You can detach from the screen session at any time by pressing:
Ctrl+a d
The programs running inside the session continue to run after you detach. You can safely close your terminal or disconnect your SSH session.
Reattach to a Screen Session
To resume a detached session, run:
screen -rIf you have multiple detached Screen sessions, Screen does not pick one for you. Instead, it prints There are several suitable screens on: followed by the list of detached sessions, and you need to specify which one to resume. To list all running sessions, run:
screen -lsThere are screens on:
3867.webserver (10/14/26 20:36:06) (Detached)
3857.backup (10/14/26 20:36:05) (Detached)
2 Sockets in /run/screen/S-linuxize.Each line shows the session ID, the date and time the session was started, and its state. The session ID is the process ID followed by the session name. Sessions started without -S get a name built from the terminal and the hostname, such as pts-0.ubuntu.
To reattach to a specific session, pass its process ID or name to the -r option:
screen -r backupIf a session is still marked as (Attached), for example after an unexpected disconnect, use -d -r to detach it first and then reattach:
screen -d -r backupTo attach to a session without detaching it from the terminal where it is already open, use -x instead. Both terminals show the same session and accept input, which is handy when you want to check on a long task from a second machine:
screen -x backupScrollback and Copy Mode
By default, Screen does not allow scrolling with the mouse wheel. To scroll through previous output, enter scrollback mode by pressing:
Ctrl+a [
In scrollback mode, use the arrow keys or Page Up / Page Down to navigate through the output buffer. To copy text, press Space to mark the start of the selection, move the cursor to the end, and press Space again to copy. To paste the copied text, press:
Ctrl+a ]
Press q or Escape to exit scrollback mode without copying.
Kill a Screen Session
To close a Screen session cleanly, type exit in each open window. When the last window is closed, the session ends automatically.
Quitting a session terminates the programs running in its windows and may lose unsaved work. Save your work first, or detach with Ctrl+a d to leave the programs running.
If the session has many windows, press Ctrl+a \ to quit. Screen asks for confirmation, then closes all windows and ends the session.
To force-kill a named session from outside, use the -X flag to send the quit command:
screen -X -S session_name quitTo kill a session by ID, replace session_name with the session ID shown by screen -ls.
Cleaning Up Dead Sessions
If a screen process crashes or gets killed, screen -ls keeps listing the session and marks it as dead:
There are screens on:
3867.webserver (10/14/26 20:36:06) (Detached)
3857.backup (10/14/26 20:32:42) (Dead ???)
Remove dead screens with 'screen -wipe'.
2 Sockets in /run/screen/S-linuxize.To remove those stale entries, run:
screen -wipeThere are screens on:
3867.webserver (10/14/26 20:36:06) (Detached)
3857.backup (10/14/26 20:32:42) (Removed)
1 socket wiped out.
1 Socket in /run/screen/S-linuxize.Screen deleted the socket of the dead backup session. Live sessions, such as webserver, are left untouched.
Customize Linux Screen
When Screen starts, it reads its configuration from /etc/screenrc and ~/.screenrc. You can modify the default settings by editing ~/.screenrc.
Here is a sample configuration with a customized status line and a few useful options:
# Turn off the welcome message
startup_message off
# Disable visual bell
vbell off
# Set scrollback buffer to 10000
defscrollback 10000
# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
Quick Reference
For a printable quick reference, see the Screen cheatsheet .
Session commands:
| Command | Description |
|---|---|
screen | Start a new session |
screen -S name | Start a named session |
screen -dmS name command | Start a detached session running a command |
screen -ls | List all sessions |
screen -r | Reattach to a detached session |
screen -r session_id | Reattach by session ID |
screen -d -r session_id | Detach and reattach to a session |
screen -x name | Attach without detaching other terminals |
screen -X -S name quit | Force kill a named session |
screen -wipe | Remove dead sessions |
Key bindings (inside a session):
| Key binding | Description |
|---|---|
Ctrl+a c | Create a new window |
Ctrl+a " | List all windows |
Ctrl+a 0–9 | Switch to window by number |
Ctrl+a A | Rename the current window |
Ctrl+a k | Kill the current window |
Ctrl+a d | Detach from session |
Ctrl+a \ | Kill all windows and end the session |
Ctrl+a [ | Enter scrollback mode |
Ctrl+a ] | Paste from scrollback buffer |
Ctrl+a ? | Show all key bindings |
Troubleshooting
There is no screen to be resumed
No detached sessions exist. Run screen -ls to view all sessions. If the session shows (Attached), use screen -d -r session_id to detach it from the stale connection and reattach.
/etc/screenrc: unknown command 'deflogin'
On Ubuntu 26.04 and Debian 13, this message flashes at the bottom of the terminal every time a session starts. Screen on these releases is built without login record (utmp) support, but the default /etc/screenrc still contains deflogin on and two login key bindings. The message is harmless. To silence it, comment out those lines:
sudo sed -i -E 's/^(deflogin|bind [IO] login)/#&/' /etc/screenrcMust run suid root for multiuser support
Screen prints this message when another user tries to attach to your session with screen -x username/session_name. Sharing a session between user accounts requires a setuid root screen binary, and Ubuntu and Debian ship it without the setuid bit, so reinstalling the package does not help. If two people need to work in the same session, have both log in as the same user and attach with screen -x session_name, or use tmux with a shared socket.
FAQ
What is the difference between Screen and tmux?
Both are terminal multiplexers that keep sessions alive after disconnecting. tmux has a more active development cycle, cleaner configuration, and better pane management. Screen is more widely pre-installed. For new setups, tmux is generally the better choice.
How do I share a Screen session with another person?
If you both log in as the same user, the second person can attach to the running session with screen -x session_name. Both terminals show the same windows and accept input, and the first person stays attached. Sharing a session between different user accounts requires a setuid root Screen binary, which Ubuntu and Debian do not ship.
How do I log a Screen session to a file?
Press Ctrl+a H to toggle logging for the current window. Screen writes the output to a file named screenlog.N in the directory where you started the session, where N is the window number. To log from the start, launch the session with screen -L -S session_name.
Conclusion
GNU Screen keeps your shell and everything running in it alive on the server, no matter what happens to your connection. If you want better pane management and easier scripting, take a look at tmux , and for a single command that does not need any interaction, nohup is often enough.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page