How to Use Linux Screen

By 

•

Updated on

•

9 min read

GNU Screen terminal multiplexer managing multiple sessions in Linux

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:

Terminal
screen --version
output
Screen version 4.09.01 (GNU) 20-Aug-23

Ubuntu 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

Terminal
sudo apt update && sudo apt install screen

Install Linux Screen on Fedora, RHEL, and Derivatives

Terminal
sudo dnf install screen

On 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:

Terminal
screen

This 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:

Terminal
screen -S session_name

It 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:

Terminal
screen -dmS backup rsync -av /home /backup

This 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+a c - Create a new window (with shell).
  • Ctrl+a " - List all windows.
  • Ctrl+a 0 - Switch to window 0 (by number).
  • Ctrl+a A - Rename the current window.
  • Ctrl+a k - Kill the current window.
  • Ctrl+a S - Split the current region horizontally into two regions.
  • Ctrl+a | - Split the current region vertically into two regions.
  • Ctrl+a Tab - Switch the input focus to the next region.
  • Ctrl+a Ctrl+a - Toggle between the current and previous window.
  • Ctrl+a Q - Close all regions except the current one.
  • Ctrl+a X - 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:

Terminal
screen -r

If 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:

Terminal
screen -ls
output
There 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:

Terminal
screen -r backup

If a session is still marked as (Attached), for example after an unexpected disconnect, use -d -r to detach it first and then reattach:

Terminal
screen -d -r backup

To 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:

Terminal
screen -x backup

Scrollback 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:

Terminal
screen -X -S session_name quit

To 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:

output
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:

Terminal
screen -wipe
output
There 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:

~/.screenrccfg
# 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}]'
GNU Screen terminal with customized status line

Quick Reference

For a printable quick reference, see the Screen cheatsheet .

Session commands:

CommandDescription
screenStart a new session
screen -S nameStart a named session
screen -dmS name commandStart a detached session running a command
screen -lsList all sessions
screen -rReattach to a detached session
screen -r session_idReattach by session ID
screen -d -r session_idDetach and reattach to a session
screen -x nameAttach without detaching other terminals
screen -X -S name quitForce kill a named session
screen -wipeRemove dead sessions

Key bindings (inside a session):

Key bindingDescription
Ctrl+a cCreate a new window
Ctrl+a "List all windows
Ctrl+a 0–9Switch to window by number
Ctrl+a ARename the current window
Ctrl+a kKill the current window
Ctrl+a dDetach 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:

Terminal
sudo sed -i -E 's/^(deflogin|bind [IO] login)/#&/' /etc/screenrc

Must 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.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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