How to Use Linux Screen

By 

Updated on

7 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? It is a common frustration for many of us. 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.

Tip
tmux is a modern alternative to Screen with similar functionality and additional features like better window management and scripting support. Both tools are excellent choices for managing terminal sessions.

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

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

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. The session shows up in screen -ls and you can attach later with screen -r backup.

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 in the range 0–9 to the new window.

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 screen sessions running, you need to specify the session ID. To list all running sessions, run:

Terminal
screen -ls
output
There are screens on:
    10835.pts-0.linuxize-desktop   (Detached)
    10366.pts-0.linuxize-desktop   (Detached)
2 Sockets in /run/screens/S-linuxize.

To reattach to a specific session, pass its ID to the -r option:

Terminal
screen -r 10835

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 10835

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.

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 the host reboots, screen -ls may keep listing the session as if it still exists. To remove those stale entries, run:

Terminal
screen -wipe

This deletes any session sockets whose backing process is no longer alive. Live sessions 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

Session commands:

CommandDescription
screenStart a new session
screen -S nameStart a named session
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 -S name quitForce kill a named session

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 [Enter scrollback mode
Ctrl+a ]Paste from scrollback buffer
Ctrl+a ?Show all key bindings

For a printable quick reference, see the Screen cheatsheet .

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.

Must run suid root for multiuser support
The screen binary does not have the required permissions. On Ubuntu and Debian, reinstall the package to restore them: sudo apt reinstall screen.

Cannot reattach to a session created by another user
Screen sessions are user-specific. You must be logged in as the same user who created the session. To share a session across users, enable multiuser mode inside Screen with Ctrl+a :multiuser on and then grant access with Ctrl+a :acladd username.

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 scroll up in Screen?
Press Ctrl+a [ to enter scrollback mode, then use the arrow keys or Page Up / Page Down to navigate. Press q or Escape to exit.

How do I share a Screen session between two users?
From inside the session, run Ctrl+a :multiuser on and then Ctrl+a :acladd username. The other user can then attach with screen -x session_id.

How do I log a Screen session to a file?
Press Ctrl+a H to toggle logging. Screen writes output to a file named screenlog.N in your home directory, where N is the window number.

Conclusion

GNU Screen lets you keep terminal sessions alive across disconnections, run multiple windows in a single session, and resume work exactly where you left off. Use screen -S name to create named sessions, Ctrl+a d to detach, and screen -r to reattach from any terminal.

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 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page