Linux Screen (also known as GNU Screen) is an essential terminal multiplexer for administrators, developers, and anyone managing long-running processes on remote servers. This guide teaches you how to install, start, name, detach, reattach, and customize Screen so you can keep jobs running after an SSH disconnect, organize multiple shells inside a single session, and create a predictable environment across systems. Whether you administrate Debian, Ubuntu, RHEL, CentOS, Fedora, or Arch, the commands and configuration patterns below will help you adopt Screen quickly and safely. The walkthrough includes practical examples, realistic outputs, common troubleshooting commands, and a sample ~/.screenrc to get you productive immediately with Linux Screen.
Check if Screen is Installed
Before installation, verify whether Screen is already available. Use the screen binary with the –version flag to report the version. This is useful for confirming compatibility and features available on your distribution.
screen --version Screen version 4.09.01 (GNU) 20-Aug-23
The command screen with the –version flag prints the installed Screen release. The output includes the version number and build date; if Screen is not installed the command will return a “command not found” error instead.
Install GNU Screen
Install Screen using your distribution package manager. On Debian and Ubuntu derivatives, run apt to update the package index and install the package. The -y flag automatically answers “yes” to prompts where shown.
sudo apt update && sudo apt install -y screen Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease ... Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: screen 0 upgraded, 1 newly installed, 0 to remove and 12 not upgraded. Need to get 590 kB of archives. After this operation, 2,100 kB of additional disk space will be used. Selecting previously unselected package screen. (Reading database ... 157460 files and directories currently installed.) Preparing to unpack .../screen_4.08.00-2_amd64.deb ... Unpacking screen (4.08.00-2) ... Setting up screen (4.08.00-2) ...
Here the combined commands update the apt cache and install the screen package. The -y flag to apt install accepts the default prompts. The output shows package retrieval, unpacking, and configuration messages.
On Fedora, CentOS Stream, and RHEL systems using dnf, install Screen with dnf as shown below. The examples include the -y flag to auto-confirm.
sudo dnf install -y screen Last metadata expiration check: 0:00:12 ago Dependencies resolved. ================================================================================ Package Arch Version Repository Size ============================================================================= Installing: screen x86_64 4.08.00-7.fc34 fedora 626 k Transaction Summary ================================================================================ Install 1 Package Total download size: 626 k Installed size: 2.0 M Is this ok [y/N]: y Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : ################################# [1/1] Installing : screen-4.08.00-7.fc34.x86_64 ################################# [1/1] Installed: screen.x86_64 0:4.08.00-7.fc34 Complete!
The dnf command installs the Screen package. The -y flag indicates “yes” to prompts. The output shows dependency resolution, download, and successful installation.
Start a Screen Session
Starting Screen without options opens a new session, creates a window running your default shell, and drops you into it. From there you can run interactive programs, background tasks, and detach when needed.
screen Screen version 4.09.01 (GNU) 20-Aug-23 Created a new screen session.
Running screen alone launches a session and opens a shell window. If Screen prints a version line and “Created a new screen session”, you are inside Screen. To view help inside Screen press Ctrl-a ? which shows keybindings and window management shortcuts.
Create a Named Screen Session
Using named sessions makes it easy to track and reattach to specific tasks. The -S flag assigns a human-friendly name to the session.
screen -S web-deploy Started screen session 'web-deploy'.
The command screen with the -S flag creates a named session “web-deploy”. Naming helps when multiple sessions run concurrently and you need to quickly reattach to the correct one.
Detach from a Session
Detach from any Screen session without killing its processes using the key sequence Ctrl-a d. After detaching your processes continue running inside their windows. You can safely disconnect your SSH session and reattach later.
List and Reattach to Screen Sessions
Use Screen's session list to identify running sessions and then reattach by PID or name. The -ls flag lists sessions. Reattach with -r followed by the session identifier or name.
screen -ls There are screens on: 10835.web-deploy (Detached) 10366.data-processing (Detached) 2 Sockets in /run/screens/$USER.
The screen command with the -ls flag outputs currently detached and attached sessions. Each line shows the PID and session name. The final line indicates how many sockets Screen uses for session management.
screen -r 10835.web-deploy Resuming session 10835.web-deploy.
Use screen with the -r flag and the session identifier or name to reattach. The output confirms resuming the specified session. If a session is attached elsewhere, you may need to use -d -r to forcibly detach it from the other location and reattach locally.
Manage Windows Inside a Session
Screen lets you create multiple windows (virtual terminals) inside a session and switch between them. Common operations are: Ctrl-a c to create a new window, Ctrl-a ” to list windows, Ctrl-a n and Ctrl-a p to move next/previous, Ctrl-a A to rename a window, and Ctrl-a 0..9 to switch by number. These key sequences are entered while inside a Screen session (press and hold Ctrl, then press a, release both, then press the specified key).
Customize Screen with .screenrc
Create a ~/.screenrc file to set sane defaults: disable the welcome message, set scrollback buffer size, and configure a persistent status line. Below is a concise example and the command to view it.
cat ~/.screenrc
# Turn off the welcome message startup_message off # Disable visual bell vbell off # Increase the scrollback buffer defscrollback 10000 # Simple 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}]' The cat ~/.screenrc command prints your per-user Screen configuration. The sample disables startup messages and visual bell, sets a 10000-line scrollback buffer, and defines a compact status line. Edit this file with your preferred editor and changes will apply to new Screen sessions.
Split Regions and Focus
Screen supports splitting the terminal into regions so you can view multiple windows side-by-side. Common key sequences inside Screen include Ctrl-a S to split horizontally, Ctrl-a | to split vertically, Ctrl-a tab to cycle focus, and Ctrl-a Q to close all other regions. Use Ctrl-a X to kill the current region. Keep in mind some terminal emulators or SSH clients may capture certain key sequences, so ensure your client passes the combinations through.
Advanced Commands and Troubleshooting
When sockets become stale or sessions are left over after abnormal shutdowns, use -wipe to remove dead sockets. If you need to force reattach from another location, use -d -r to detach elsewhere and attach locally.
screen -wipe Removing dead screens: 2 Sockets in /run/screens/$USER cleaned.
screen with the -wipe flag scans the socket directory and removes stale session records. The output confirms cleanup. Use this when screen -ls lists sessions that no longer exist or that refuse to attach.
Best Practices for Production Use
Adopt clear session naming (include project or task), keep .screenrc under version control, and set a generous defscrollback so logs can be inspected after the fact. For automated jobs, consider running commands inside Screen launched from systemd user units or from cron to ensure they restart on failure. For daily interactive work, keybindings and a readable hardstatus line speed navigation.
Security Considerations
Screen uses Unix domain sockets under /run/screens or /var/run/screens and inherits user permissions; other users cannot access your sessions unless they have root privileges. Avoid running untrusted binaries inside Screen and keep SSH and Screen packages up to date to benefit from fixes. If you need to share a session, consider using tmux with attach permissions or use Screen's multiuser features after setting proper ACLs.
Conclusion
GNU Screen is a reliable, battle-tested utility for keeping terminal sessions alive and organizing multiple shells on a single server. With the commands and configuration patterns shown here you can install Screen, create named sessions, detach and reattach safely, manage windows and regions, and customize behavior through ~/.screenrc. For teams or automation workflows that require persistent shells, Screen remains a practical choice — simple to adopt and widely available across Linux distributions. If you need richer scripting or more modern features, evaluate tmux as an alternative, but for straightforward, stable session persistence, Screen continues to serve administrators and developers well.