Detach and Reattach
Ctrl+a is screen's command key: press Ctrl+a, release, then the letter. Detaching leaves everything running; is what actually ends things.
| Command | What it does |
|---|---|
| Detach, leaving the session and its jobs running | |
| Detach and log out of the shell that started screen | |
| Reattach to the detached session | |
| Reattach to a session by name (or PID) | |
| Detach it from wherever it is attached, then reattach here | |
| Attach without detaching anyone; both of you see the same screen | |
| Reattach to the first session found, creating one if none exist | |
| Detach a session from outside it | |
| Close the current window; closing the last one ends the session |
A dropped SSH connection detaches you automatically, so a long job inside screen survives it; gets you back in. To stop the drops themselves, see ssh broken pipe.
Sessions
| Command | What it does |
|---|---|
| Start a new session | |
| Start a session named deploy, which beats PIDs for reattaching | |
| List sessions and whether each is Attached or Detached | |
| Start a detached session running a command (scripts, cron) | |
| Type a command into a session from outside | |
| Rename the current session | |
| Remove sessions marked Dead from the list |
Run in the Background
(or with a name) starts a session already detached, which is how scripts, cron jobs, and game servers get a shell that outlives the login.
| Command | What it does |
|---|---|
| Run a script in a detached session named backup | |
| Keep the window open after the command exits, so you can read the error | |
| Same, logging output to screenlog.0 | |
| Open another window running a command in a session that already exists | |
| Send a line to the session as if you typed it | |
| Send it to window 0 specifically (how people stop a Minecraft server) | |
| Check whether the background session is still alive |
A detached session is owned by your login, so it dies with a reboot and with an aggressive user-session cleanup. Anything that must come back on its own belongs in a service unit rather than screen.
Kill a Session
| Command | What it does |
|---|---|
| Kill the current window (asks first) | |
| Kill every window and end the session (asks first) | |
| Kill a session from outside, without attaching | |
| Close windows one at a time; the session ends with the last one |
Kill every detached session at once:
screen -ls | grep Detached | cut -d. -f1 | xargs -r killScrolling and Copy Mode
PgUp and the mouse wheel talk to your terminal, not to screen. Scrolling back happens in copy mode.
| Command | What it does |
|---|---|
| or | Enter copy mode |
| , , , | Scroll (, , , also work) |
| and | Jump to the top or bottom of the buffer |
| and | Search forward and backward |
| Start selecting; a second or copies and exits | |
| or | Leave copy mode without copying |
| Paste what you copied | |
| Bigger buffer for the current window |
The default buffer is only 100 lines. Put in so every window starts with real history.
Windows
Windows are full-screen tabs inside one session.
| Command | What it does |
|---|---|
| New window | |
| and | Next and previous window |
| to | Jump to a window by number |
| Pick a window from a list | |
| Show the window list in the message line | |
| Rename the current window | |
| Toggle between the two most recent windows | |
| Alert when this window shows activity | |
| Alert when this window goes silent for 30 seconds | |
| Kill the window (asks first) |
Split Screen
A new region starts empty: move into it with , then open a window in it.
| Command | What it does |
|---|---|
| Split top and bottom (capital S) | |
| Split left and right | |
| Move to the next region | |
| Open a new window in the empty region ( picks an existing one) | |
| Close the current region; its window keeps running | |
| Close every region except the current one | |
| Set the current region to 20 lines | |
| Grow or shrink it by 5 ( the other way) | |
| Give every region the same size | |
| Redraw after the terminal window itself changed size |
Keyboard Shortcuts
The rest of the keys worth knowing.
| Key | Action |
|---|---|
| List every keybinding | |
| Send a literal Ctrl+a through (start of line in bash) | |
| Command prompt for screen's own commands | |
| Lock the session behind your password | |
| Start or stop logging the window | |
| Write a snapshot of the visible window to hardcopy.0 | |
| List the displays attached to this session |
Serial Ports
screen doubles as a serial terminal, which is the main thing it does that tmux does not. Settings default to 8N1; give the baud rate after the device.
| Command | What it does |
|---|---|
| Serial console at 115200 baud (Raspberry Pi, ESP32, most dev boards) | |
| Arduino-style boards that show up as ACM | |
| macOS device names live under | |
| Close the serial session and free the port |
Detaching with keeps the port locked, so end serial sessions with . Permission denied on the device means your user is not in the right group: , then log in again.
Logging
| Command | What it does |
|---|---|
| Log everything to screenlog.0 in the current directory | |
| Log to a file you name (screen 4.6 and newer) | |
| Start or stop logging from inside a session | |
| One-off snapshot of the visible window to hardcopy.0 | |
| In : log every window from the start |
Install
"screen: command not found" means the package is missing, which is normal on minimal images and containers.
| Command | What it does |
|---|---|
| Debian, Ubuntu, Raspberry Pi OS | |
| Fedora, RHEL, Rocky, AlmaLinux ( on CentOS 7) | |
| Alpine | |
| Arch | |
| macOS, replacing the 2006-era build Apple ships | |
| Print the version, to confirm which one you got | |
| Show which copy of screen is first in |
macOS still has at version 4.00.03, which is missing and a lot of the copy-mode keys. Homebrew's build lands in ahead of it.
PuTTY and WSL
Windows has no screen of its own. You either run it on the Linux box you connect to, or run it locally under WSL.
| Command | What it does |
|---|---|
| then | Run screen locally in a WSL distro (install it there with ) |
| Run it on the remote host after connecting; PuTTY only carries the keys | |
| Send a literal Ctrl+a, needed because PuTTY passes Ctrl+a straight through |
PuTTY has its own serial mode, so on Windows you pick a COM port there instead of . The PuTTY cheat sheet covers the Windows side.
screen vs tmux
The keys map almost one to one, so switching either way is cheap. tmux has better splits, a status bar, and active development; screen is preinstalled more often and handles serial ports. The tmux cheat sheet covers the other side in full.
| screen | tmux |
|---|---|
| , | , |
| and | and |
Gotchas
- Detach is not exit. keeps everything running; closes the window, and the last window takes the session with it ("[screen is terminating]").
- The scrollback buffer defaults to 100 lines. Add to before you need it, not after.
- screen eats Ctrl+a, which bash uses for start of line. Press to send it through, or move the command key with in .
- "There is no screen to be resumed" while shows a session Attached means a dead client is holding it. takes it over.
- screen inside screen (a session on the far end of an SSH window): detaches the inner one, the outer.
- Sessions do not survive a reboot. screen protects you from disconnects, not from restarts; anything that must outlive a reboot belongs in a systemd service.