GNU Screen

Screen is a terminal multiplexer — it lets a single terminal window run multiple shell sessions, and, crucially, keeps them alive after you disconnect. Start a long job over SSH, detach, close your laptop, reconnect from anywhere, and reattach exactly where you left off. For anyone administering remote servers, it's the difference between a dropped connection killing a six-hour job and simply picking it back up. This guide covers installation, the detach/reattach workflow that makes it indispensable, and the window and split-screen features underneath.

Tool: GNU Screen  ·  Type: terminal multiplexer  ·  Prefix: Ctrl-a  ·  Config: ~/.screenrc
01 — Why Screen Exists

A normal shell is bound to its terminal: close the terminal or drop the SSH link, and every process started from it receives a hangup and dies. Screen breaks that link. It runs a persistent session on the server that your terminal merely attaches to — detaching leaves everything running on the server, untouched.

ProblemHow Screen solves it
SSH drops mid-jobThe job runs inside Screen on the server, unaffected — reattach and it's still going
One terminal, many tasksMultiple windows inside one session; switch between them with a keystroke
Long tasks on a remote boxStart it, detach, log off entirely; check back hours later
Sharing a live sessionTwo people can attach to the same session and see the same screen
ℹ  Screen and tmux solve the same problem; Screen is older, is preinstalled or one package away almost everywhere, and has a simpler mental model. If a server has one multiplexer already, it's often Screen — worth knowing regardless of which you prefer.
02 — Install

Screen is in every mainstream distribution's default repositories. Pick the line for your package manager.

Debian / Ubuntu
sudo apt update && sudo apt install -y screen
RHEL / CentOS / Fedora / Rocky / Alma
sudo dnf install -y screen # older systems: sudo yum install -y screen
Arch
sudo pacman -S screen
openSUSE
sudo zypper install screen
macOS (preinstalled, or newer via Homebrew)
brew install screen
Verify
screen --version
ℹ  macOS ships an older Screen at /usr/bin/screen; the Homebrew build is newer if you need current features. On minimal container images Screen usually isn't present — the one-line install above adds it.
03 — The Prefix Key

Screen listens for commands after a prefix key: Ctrl-a. Every Screen command is that prefix, released, then a second key. Throughout this guide Ctrl-a d means "press Ctrl and a together, let go, then press d."

NotationMeans
Ctrl-a dPrefix, then d — detach
Ctrl-a ?Prefix, then ? — show the built-in key bindings help
Ctrl-a Ctrl-aPrefix twice — jump to the previous window
⚠  Ctrl-a is also the "jump to start of line" shortcut in Bash/Emacs editing. Inside Screen that keystroke is intercepted — to send a literal Ctrl-a to the shell (to move the cursor), press Ctrl-a a. This surprises people the first time; it's the one ergonomic cost of Screen's default prefix.
04 — The Core Workflow: Detach & Reattach

This is the feature you came for. Name your sessions so you can find them again — an unnamed session is fine for one, painful for several.

Start a named session
screen -S deploy

You're now inside Screen — it looks like an ordinary shell. Start something long-running (a backup, a build, a download), then detach and the session keeps running on the server without you.

Detach — leaves everything running
Press: Ctrl-a d
List running sessions
screen -ls # There is a screen on: # 4123.deploy (Detached)
Reattach — by name or by PID
screen -r deploy # by name screen -r 4123 # by the PID shown in -ls
✓  The whole point: after Ctrl-a d you can close the terminal, log out of SSH, shut your laptop — the session and its processes live on the server. Reconnect later, screen -r deploy, and you're back as if you never left.
ℹ  If a session is stuck as "Attached" (e.g. your SSH died without a clean detach), force it: screen -d -r deploy detaches it elsewhere and reattaches here. screen -x deploy instead attaches alongside — both terminals share one live view.
05 — Windows Inside a Session

One session can hold many windows — independent shells you flip between without opening new SSH connections. Each is numbered from 0.

KeysAction
Ctrl-a cCreate a new window
Ctrl-a nNext window
Ctrl-a pPrevious window
Ctrl-a 09Jump straight to window by number
Ctrl-a "Show a selectable list of all windows
Ctrl-a ARename the current window
Ctrl-a wShow the window list in the status line
Ctrl-a kKill the current window (asks to confirm)
ℹ  A typical layout: window 0 for an editor, window 1 tailing a log, window 2 a free shell for commands. Ctrl-a " gives you a menu when you've lost track of what's where. Closing the last window ends the session.
06 — Splitting the Screen

Beyond switching windows, Screen can divide the terminal into regions so you see multiple windows at once — log on top, shell below, for instance.

KeysAction
Ctrl-a SSplit horizontally (top / bottom) — capital S
Ctrl-a |Split vertically (left / right)
Ctrl-a TabMove focus to the next region
Ctrl-a XClose the focused region (capital X)
Ctrl-a QClose all regions but the focused one
⚠  A fresh region is empty — splitting doesn't duplicate the current window into it. After Ctrl-a S, move focus with Ctrl-a Tab, then either create a window there with Ctrl-a c or select an existing one with Ctrl-a and its number. Regions are just viewports onto your windows.
07 — Scrollback, Copy & Logging

Screen keeps its own scrollback buffer (your terminal's scroll wheel won't work as expected inside it). Enter copy mode to scroll back and select text.

KeysAction
Ctrl-a EscEnter copy / scrollback mode (then arrows / PgUp to scroll)
SpaceIn copy mode: start selection, then Space again to copy
Ctrl-a ]Paste the copied text
EscLeave copy mode
Ctrl-a HToggle logging the window to a screenlog.n file (capital H)
Bump the scrollback size in ~/.screenrc
defscrollback 10000
ℹ  Increase scrollback well beyond the tiny default so copy mode is actually useful. Ctrl-a H is handy for capturing the full output of a long job to a file while you watch it live.
08 — Configuration & Handy Flags

Screen reads ~/.screenrc at startup. A few lines make it far friendlier — a persistent status bar and bigger scrollback are the usual first additions.

~/.screenrc starter
# Bigger scrollback buffer defscrollback 10000 # Always-on status line: window list left, host + time right hardstatus alwayslastline hardstatus string '%{= kG}[ %H ]%{= kw} %-w%{+b yk} %n %t %{-}%+w %=%{= kG}%c %Y-%m-%d' # Turn off the startup license message startup_message off # Bigger visual bell instead of an audible beep vbell on
Useful command-line flags
CommandDoes
screen -S nameStart a session with a name
screen -lsList sessions
screen -r nameReattach to a session
screen -d -r nameForce-detach elsewhere, then reattach here
screen -x nameAttach alongside (shared view)
screen -dmS name cmdStart a named session detached, running cmd (great for scripts/cron)
screen -S name -X quitKill a named session from outside it
09 — Quick Reference
Keys / CommandAction
Ctrl-a dDetach (leave running)
Ctrl-a cNew window
Ctrl-a n / pNext / previous window
Ctrl-a "Window list
Ctrl-a ARename window
Ctrl-a S / |Split horizontal / vertical
Ctrl-a TabSwitch region
Ctrl-a EscScrollback / copy mode
Ctrl-a ?Key bindings help
screen -S nameStart named session
screen -lsList sessions
screen -r nameReattach
screen -dmS name cmdStart detached running a command
✓  Stuck? Ctrl-a ? shows every binding without leaving your session. To leave Screen entirely, exit each shell (exit / Ctrl-d) until the session closes — that terminates it, unlike detaching.