GNU Screen is a terminal multiplexer for Linux and other Unix-like systems that runs several shell sessions inside one terminal and keeps them alive when the user disconnects. In the Shell & terminal toolset, it sits between the terminal emulator and the programs it hosts, so a long build, a database migration or an interactive editor survives a dropped SSH connection or a closed laptop lid.
First released in 1987 and maintained by the GNU Project, Screen is often invoked simply as screen. It is installed by default or available as a standard package on nearly every Linux distribution, which makes it a dependable choice on servers where newer tools such as tmux may be missing.
How GNU Screen keeps sessions alive
Screen works by splitting the terminal experience into a persistent server process and a disposable client attachment. When a user starts screen, the program creates a session server that owns one or more pseudo-terminals (PTYs), each running its own shell, and a client that draws the active window on the real TTY.
Because the shells are children of the Screen server rather than of the login session, closing the terminal does not send SIGHUP to them. The client can detach, leaving the server running in the background, and a later client can reattach from the same machine or from a new SSH login. The server and client communicate through a named socket, usually under /run/screen/S-username or a directory set by the SCREENDIR variable.
Screen also maintains its own virtual terminal emulation, based on the VT100 and ANSI standards. It interprets the escape sequences that programs send, stores the resulting screen state and redraws it on attach, which is why the window content reappears intact after reconnection.
The table below summarizes the main components and the role each one plays.
| Component | What it is | Role |
|---|---|---|
| Session | A named Screen server process | Owns all windows and survives detach |
| Window | One pseudo-terminal with a shell or program | Runs a single job, numbered from 0 |
| Region | A visible area of the display after a split | Shows one window at a time |
| Socket | A named pipe or Unix socket file | Connects clients to the session server |
| Scrollback buffer | Stored lines of past output per window | Allows review and copy of history |
Essential commands and key bindings
Screen is controlled through a command prefix, by default Ctrl-a, followed by a single key. This prefix is captured by Screen and never reaches the shell, which is the reason that the Bash shortcut for moving to the start of a line must be typed as Ctrl-a a inside a session.
The following table lists the commands that cover most daily work, from starting a session to sharing it.
| Action | Command or keys | Effect |
|---|---|---|
| Start a named session | screen -S build | Creates a session called build |
| List sessions | screen -ls | Shows session IDs and attached or detached state |
| Detach | Ctrl-a d | Leaves the session running in the background |
| Reattach | screen -r build | Connects to a detached session |
| Force reattach | screen -d -r build | Detaches another client first, then attaches |
| New window | Ctrl-a c | Opens another shell in the session |
| Switch window | Ctrl-a n or Ctrl-a 0-9 | Moves to the next or a numbered window |
| Split horizontally | Ctrl-a S | Divides the display into two regions |
| Copy mode | Ctrl-a [ | Scrolls back and selects text |
| Log output | Ctrl-a H | Writes window output to a screenlog file |
Configuration lives in `~/.screenrc` for each user and /etc/screenrc system-wide. Common settings include a larger `defscrollback` value, a `hardstatus` line that shows window names and the clock, and startup_message off to skip the banner.
GNU Screen compared with tmux and other approaches
The closest neighbor of Screen is tmux, a newer terminal multiplexer that solves the same problem with a client-server design built from the start, a scriptable command interface and more flexible pane layouts. The choice between them is usually a matter of availability, habit and scripting needs rather than capability.
The comparison below covers the alternatives that administrators most often weigh against Screen.
| Tool | Persistence after disconnect | Split views | Best fit |
|---|---|---|---|
| GNU Screen | Yes, via detach and reattach | Horizontal and vertical | Legacy servers and serial consoles |
| tmux | Yes, via detach and reattach | Flexible panes and layouts | Daily multiplexing and scripting |
| nohup | Yes, but no interactive access | No | One unattended background command |
| systemd-run | Yes, as a transient unit | No | Managed services with logging |
| Terminal tabs | No, they close with the client | Depends on emulator | Local desktop work only |
Screen keeps a few distinct strengths. It can attach directly to a serial device with a command such as screen /dev/ttyUSB0 115200, which makes it a lightweight console for routers, embedded boards and server management ports. It also offers multiuser mode, in which several accounts can attach to one session with access control lists.
Practical use on Linux servers
The typical workflow is simple: start a named session before any long task, run the job, detach and reconnect later. Naming sessions avoids the confusion of numeric IDs when several sessions exist on one host.
The decision table below maps common situations to a recommended approach.
| Situation | Recommended approach | Reason |
|---|---|---|
| Kernel compile over unstable SSH | Run inside a named session | Survives connection drops |
| Unattended script at boot | screen -dmS name command | Starts detached without a terminal |
| Pair troubleshooting | Multiuser mode with acladd | Two users see the same shell |
| Router console over USB | screen /dev/ttyUSB0 9600 | Acts as a serial terminal |
| Production service | Use a systemd unit instead | Gives restart policy and journal logs |
- Use `screen -dmS` to launch a detached job from a script or cron entry.
- Use `screen -X -S name` followed by a Screen command to control a running session remotely.
- Use `screen -x` to attach a second client to an already attached session for shared viewing.
Limitations and common mistakes
Screen is reliable, but its age shows. Development was slow for many years, so features such as true color support, vertical splits and Unicode handling arrived late, and some distributions shipped old versions. Several Linux distributions now install tmux by default and treat Screen as optional.
Most problems that users report come from a small set of causes, listed below.
| Symptom | Cause | Fix |
|---|---|---|
| Session lost after reboot | Screen keeps sessions only in memory | Use a service manager for durable jobs |
| Shell ignores Ctrl-a | Prefix captured by Screen | Type Ctrl-a a or remap with escape |
| Session marked dead | Server process was killed | Remove the stale socket with screen -wipe |
| Cannot reattach | Session still attached elsewhere | Use screen -d -r to take it over |
| Jobs killed on logout | systemd-logind KillUserProcesses enabled | Enable lingering or adjust the setting |
A frequent misconception is that Screen makes processes permanent. It only protects them from terminal disconnection; a reboot, an out-of-memory kill or a session cleanup policy still ends them. Multiuser mode also requires care, because a misconfigured access list can give another account full shell access with your privileges.
Put simply
GNU Screen is like a waiting room for your command line. You open your work inside it, and if your connection breaks or you close the window, the work keeps running in the room. When you come back, you step in again and everything is exactly where you left it.
It also lets one window hold several command lines at once, so you can switch between them with a keystroke. The key takeaway is that Screen protects long tasks from dropped connections, but it does not protect them from a computer restart.
In practice
A systems administrator needs to copy 2 TB of archive data between two storage servers in a data center. The transfer with rsync is expected to take about nine hours, and the administrator works from a laptop over a VPN that disconnects every evening.
She logs in over SSH, types screen -S archive-sync, starts the rsync command and presses Ctrl-a d to detach the session. She also opens a second window with Ctrl-a c to watch disk usage with df -h. When the VPN drops at 18:00, the transfer continues untouched on the server.
The next morning she reconnects, runs screen -r archive-sync and sees the final rsync summary on screen. The copy finished without a single restart, and she closes the session with exit in each window.