How to Use GNU Screen on a Linux VPS

14 min read·Matthieu|

Learn GNU Screen from installation to daily use. Manage sessions, split regions, configure .screenrc, and keep processes running after SSH disconnects on Debian 12 and Ubuntu 24.04.

You SSH into your server, start a long-running process, and your connection drops. The process dies. GNU Screen solves this. It runs terminal sessions that persist independently of your SSH connection. You can detach, disconnect, reconnect hours later, and pick up exactly where you left off.

This tutorial covers GNU Screen from installation to daily workflows on Debian 12 and Ubuntu 24.04. You will learn session management, window handling, split regions, copy mode, and .screenrc customization.

What Is GNU Screen?

GNU Screen is a terminal multiplexer. It creates virtual terminal sessions that run on the server, independent of your SSH connection. Inside one Screen session, you can open multiple windows, split your terminal into regions, and scroll back through output history.

Screen sits between your SSH client and the shell. When you detach from a Screen session, all programs inside it keep running. When you reattach, you see the same output, same running processes, same state. This makes it essential for any work on a remote VPS where SSH connections can drop unexpectedly.

Screen has been around since 1987. It ships in the default repositories of every major Linux distribution. The current versions are 4.9.0 on Debian 12 and 4.9.1 on Ubuntu 24.04.

How Do You Install GNU Screen on Debian and Ubuntu?

Screen is available in the default repositories on both Debian 12 and Ubuntu 24.04. Install it with a single apt command. On most minimal VPS images, it is not pre-installed.

Update the package index and install Screen:

sudo apt update && sudo apt install -y screen

Verify the installation:

screen --version

On Debian 12, you will see:

Screen version 4.09.00 (GNU) 30-Jan-21

On Ubuntu 24.04:

Screen version 4.09.01 (GNU) 20-Aug-23

If you see a version number, Screen is ready to use.

How Do You Start and Name a Screen Session?

To start a new Screen session, run screen. But starting without a name makes it harder to identify later. Always name your sessions with the -S flag.

Start a named session:

screen -S myproject

Your terminal clears and you are now inside a Screen session. Everything you run here persists even if your SSH connection drops.

Verify you are inside a Screen session:

echo $STY

This prints the session name. If it shows something like 12345.myproject, you are inside Screen. If it prints nothing, you are not in a session.

Screen Command Reference

All Screen commands start with the prefix key Ctrl-a, followed by another key. This prefix is called the "escape character."

Shortcut Action Notes
Ctrl-a d Detach from session Session keeps running
Ctrl-a c Create new window Opens a new shell
Ctrl-a n Next window Cycles forward
Ctrl-a p Previous window Cycles backward
Ctrl-a " List windows Select with arrow keys
Ctrl-a A Rename current window Type new name, press Enter
Ctrl-a k Kill current window Asks for confirmation
Ctrl-a S Split horizontally Capital S
Ctrl-a | Split vertically Pipe character
Ctrl-a Tab Switch between regions Cycles through splits
Ctrl-a X Close current region Capital X
Ctrl-a [ Enter copy mode Also Ctrl-a Esc
Ctrl-a ] Paste copied text Pastes from buffer
Ctrl-a ? Show key bindings Built-in help

How Do You Detach and Reattach a Screen Session?

This is the core workflow. You start a process in Screen, detach, and the process keeps running. Later, you reattach to check on it.

Detach from your current session:

Press Ctrl-a then d.

You will see:

[detached from 12345.myproject]

Your session is now running in the background. You can safely close your SSH connection.

List all sessions:

screen -ls

Output:

There are screens on:
	12345.myproject	(03/19/2026 02:15:30 PM)	(Detached)
1 Sockets in /run/screen/S-your_user.

Reattach to a session:

screen -r myproject

You are back in your session with all output and processes intact.

If you have only one detached session, screen -r without a name works too.

How Do You Force Reattach When a Session Is Already Attached?

Sometimes a session shows as (Attached) even though you are not connected. This happens when SSH drops without a clean disconnect. Screen still thinks the old connection is active.

Use this decision table to pick the right flags:

Scenario Command What it does
Session shows "Attached" but you are not connected screen -D -r myproject Force-detaches the old connection, then reattaches here
Session shows "Attached" and you want to share it screen -x myproject Attaches without detaching the other connection (multi-display)
Session shows "Attached", you want to steal it screen -d -r myproject Detaches the remote side, reattaches locally

The most common case is screen -D -r. It handles stale connections from crashed SSH sessions.

Verify the session state after reattaching:

screen -ls

The session should now show (Attached).

How Do You Keep a Process Running After SSH Disconnect?

Start a Screen session, run your process inside it, and detach. The process survives SSH disconnects, network drops, and even closing your laptop.

Here is the full workflow:

screen -S training

Inside the session, start your long-running process:

python3 train_model.py --epochs 100

Detach with Ctrl-a d. You will see:

[detached from 12345.training]

Close SSH. Go make coffee. Come back later:

ssh user@your-server
screen -r training

Your training job is still running, and you can see all the output it produced while you were away.

How Do You Manage Multiple Windows in Screen?

A single Screen session can hold multiple windows. Each window is an independent shell. Think of windows like tabs in a web browser.

Create a new window inside your session:

Press Ctrl-a c.

A new shell opens. Your previous window is still there. Switch between windows:

  • Ctrl-a n moves to the next window
  • Ctrl-a p moves to the previous window
  • Ctrl-a 0 through Ctrl-a 9 jumps to window by number
  • Ctrl-a " shows a list of all windows. Use arrow keys to select one and press Enter.

Rename the current window for easier identification:

Press Ctrl-a A, type a name, and press Enter.

Check which window you are in:

Press Ctrl-a " to see the window list. The current window has an asterisk.

Close a window by typing exit in its shell, or press Ctrl-a k and confirm with y.

How Do You Split the Terminal into Regions?

Screen can split your terminal into multiple regions, each showing a different window. This is useful for monitoring logs in one pane while working in another.

Building a Monitoring Layout Step by Step

Let's build a 3-pane layout: a main shell on top, logs on the bottom-left, and system monitoring on the bottom-right.

Step 1: Start a named session:

screen -S monitor

Step 2: Split horizontally. Press Ctrl-a S (capital S).

Your terminal splits into a top and bottom region. The cursor stays in the top region.

Step 3: Move to the bottom region. Press Ctrl-a Tab.

The bottom region is empty. You need to assign a window to it.

Step 4: Create a new window in the bottom region. Press Ctrl-a c.

Now you have a shell in the bottom region.

Step 5: Split the bottom region vertically. Press Ctrl-a | (pipe character).

The bottom half now has a left and right section. Move to the new right section with Ctrl-a Tab.

Step 6: Create another window. Press Ctrl-a c.

Step 7: Start your monitoring tools. Navigate between regions with Ctrl-a Tab:

  • Top region: your main working shell
  • Bottom-left: run tail -f /var/log/syslog
  • Bottom-right: run htop

Region Management Commands

Shortcut Action
Ctrl-a S Split horizontally
Ctrl-a | Split vertically
Ctrl-a Tab Move to next region
Ctrl-a X Close current region (window stays open)
Ctrl-a Q Close all regions except current
Ctrl-a :resize +5 Grow current region by 5 lines
Ctrl-a :resize -5 Shrink current region by 5 lines

One thing to know: Screen does not save your region layout when you detach. When you reattach, all splits are gone and you see a single window. The windows themselves (and their processes) are preserved. You need to re-split manually. If you want persistent layouts, add layout commands to your .screenrc or consider tmux, which preserves pane layouts on detach.

How Do You Use Copy Mode and Scrollback?

By default, you cannot scroll up in a Screen session with your mouse wheel or Shift-PgUp. Screen captures all input. To view previous output, you need to enter copy mode.

Enter copy mode by pressing Ctrl-a [ or Ctrl-a Esc.

You are now in a vi-like navigation mode:

Key Action
Arrow keys Move cursor
h/j/k/l Move cursor (vi-style)
Ctrl-u Scroll up half page
Ctrl-d Scroll down half page
0 Beginning of line
$ End of line
g Go to top of scrollback
G Go to end of scrollback
/ Search forward
? Search backward
Space Set mark (start/end of selection)
Enter Copy selected text and exit copy mode
Esc Exit copy mode without copying

To copy text: enter copy mode, move to the start of the text you want, press Space to set the first mark, move to the end, press Space again. The text is copied to Screen's paste buffer.

To paste: press Ctrl-a ].

The default scrollback buffer holds 100 lines. That's too few for real work. Increase it in your .screenrc:

defscrollback 10000

This gives you 10,000 lines of scrollback per window.

How Do You Configure Screen with .screenrc?

Screen reads ~/.screenrc on startup. This file controls default behavior, key bindings, the status bar, and startup windows.

What Does a Good .screenrc Look Like?

Here is a complete .screenrc with each directive explained:

# Disable the startup splash message
startup_message off

# Use bash as the default shell
shell /bin/bash

# Set scrollback buffer to 10,000 lines
defscrollback 10000

# Use 256-color terminal
term screen-256color

# Disable visual bell (use audible bell instead)
vbell off

# Enable alternate screen support (clears screen after less/vim exit)
altscreen on

# Status bar at the bottom of the screen
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][ %=%{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][ %{B}%Y-%m-%d %{W}%c %{g}]'

# Detach on hangup (SSH disconnect)
autodetach on

# Don't block the whole session if a window goes unresponsive
nonblock on

# Log new screen windows in utmp
deflogin on

# Start window numbering at 1 instead of 0
bind c screen 1
bind ^c screen 1
bind 0 select 10

# Named windows at startup
screen -t shell 1
screen -t logs 2
screen -t work 3

Create this file:

nano ~/.screenrc

Paste the configuration above and save.

Hardstatus Format String Explained

The hardstatus line is the most powerful (and confusing) part of .screenrc. Here is what each token in the example means:

Token Meaning
%{= kG} Set color: black background, bright green text
%H System hostname
%-Lw All windows before the current one
%{r}(%{W}%n*%f%t%{r}) Current window: red parens, white window number + flags + title
%+Lw All windows after the current one
%Y-%m-%d Date in YYYY-MM-DD format
%c Current time in HH:MM

Color codes: k black, r red, g green, y yellow, b blue, m magenta, c cyan, w white. Capitalize for bright/bold variants.

Start a new session to see the status bar:

screen -S test

You should see a green status bar at the bottom showing your hostname, window list, and the current date and time.

Changing the Escape Key

If Ctrl-a conflicts with your workflow (it is also "go to beginning of line" in bash), you can rebind it:

# Use Ctrl-j as the escape key instead of Ctrl-a
escape ^Jj

After this change, all Screen commands use Ctrl-j instead of Ctrl-a. Pick a key you rarely use.

What Are Common GNU Screen Workflows on a VPS?

Keep a Deployment Running

screen -S deploy
./deploy.sh --production
# Ctrl-a d to detach

Check later:

screen -r deploy

Monitor Multiple Log Files

screen -S logs

Inside the session:

  1. Ctrl-a S to split horizontally
  2. In the top region: tail -f /var/log/nginx/access.log
  3. Ctrl-a Tab to move to bottom
  4. Ctrl-a c for a new window
  5. tail -f /var/log/nginx/error.log

Run a Long Training Job (AI Developers)

screen -S training
python3 -u train.py --model llama --epochs 50 2>&1 | tee training.log
# Ctrl-a d to detach

The -u flag disables Python output buffering so you see output in real time when you reattach. Piping through tee saves output to a file as a backup.

Quick Detach-and-Reconnect After SSH Drop

If your SSH drops while inside Screen, simply reconnect:

ssh user@your-server
screen -D -r

screen -D -r finds your session, force-detaches the stale connection, and reattaches.

GNU Screen vs tmux: Which Should You Use?

Screen and tmux are both terminal multiplexers. They solve the same core problem. Here is an honest comparison:

Feature GNU Screen tmux
First release 1987 2007
License GPL-3.0 ISC (BSD-like)
Active development Slow (5.0 released Aug 2024 after years of inactivity) Active (regular releases)
Pane layout persistence Lost on detach Preserved on detach
Default key prefix Ctrl-a Ctrl-b
Configuration .screenrc (custom syntax) .tmux.conf (custom syntax)
Plugin ecosystem None Large (tpm, tmux-resurrect, etc.)
RHEL/Fedora status Removed since RHEL 8 Included by default
Serial port support Yes (screen /dev/ttyUSB0) No
Learning resources Mature but dated Abundant and current

When to use Screen:

  • You need serial port access (screen /dev/ttyUSB0 115200)
  • You are on an older system where Screen is pre-installed and tmux is not
  • You need a simple detach/reattach workflow and nothing more

When to use tmux:

  • You want persistent pane layouts that survive detach
  • You want an active plugin ecosystem
  • You are on RHEL 8+ or Fedora (Screen is not in the repositories)
  • You need scripted window/pane creation

Both tools handle the core use case (keep processes alive after SSH disconnect) equally well. If you are starting fresh, tmux has more momentum and better defaults. If Screen is already part of your workflow, there is no pressing reason to switch. See our tmux tutorial for a full walkthrough.

Troubleshooting Common Screen Issues

"There is a screen on ... (Attached)" but you are not connected

This happens after an SSH crash. The old connection did not cleanly detach.

screen -D -r session_name

This force-detaches the ghost connection and reattaches your terminal.

Dead sessions in the list

Sometimes sessions show as (Dead) after a server reboot or crash.

screen -wipe

Output:

There are screens on:
	12345.old_session	(Dead ???)
Removed dead screens.
1 socket wiped out.

This removes stale socket files. Run screen -ls to confirm they are gone.

Terminal is frozen / not accepting input

You probably pressed Ctrl-a s by accident. This is the XOFF flow control signal that pauses terminal output.

Fix it:

Ctrl-a q

This sends XON to resume output. If you never use flow control, disable it in your .screenrc:

defflow off

Screen shows garbled characters

Your terminal and Screen disagree on encoding or color support. Add to your .screenrc:

defutf8 on
term screen-256color

Then start a new session. Existing sessions will not pick up .screenrc changes.

Where are Screen's logs?

Screen itself does not log to a system log. To enable per-window logging:

Ctrl-a H

This toggles logging for the current window. Logs are saved to screenlog.N in the directory where you started the session. The N matches the window number.

To check if Screen is running at the system level:

ps aux | grep screen

Common CLI Flags Reference

Flag Description Example
-S name Start a named session screen -S myapp
-r [name] Reattach to a detached session screen -r myapp
-d -r name Detach remote, reattach here screen -d -r myapp
-D -r name Force-detach and reattach screen -D -r myapp
-x name Attach to an already attached session (multi-display) screen -x myapp
-ls List all sessions screen -ls
-wipe Remove dead sessions screen -wipe
-X command Send a command to a running session screen -S myapp -X quit
-dmS name Start a detached named session screen -dmS daemon
-L Enable logging from start screen -L -S myapp

Starting a session in detached mode (-dmS) is useful for scripts and systemd units that need to launch Screen sessions without an interactive terminal.


Copyright 2026 Virtua.Cloud. All rights reserved. This content is original work by the Virtua.Cloud team. Reproduction, republication, or redistribution without written permission is prohibited.

Ready to try it yourself?

Deploy your own server in seconds. Linux, Windows, or FreeBSD.

See VPS Plans
How to Use GNU Screen on a Linux VPS (2026)