Working with Screen

Guide to running and managing programs in the background on Linux.

Screen is a powerful terminal multiplexer that lets you run programs in detached sessions, disconnect from them without killing the process, and reconnect later. This is incredibly useful when working with VPS or dedicated servers via SSH: you can start long-running tasks (e.g., updates, parsing, mining, or server-side apps), detach, and come back even after a connection drop.

Screen creates virtual terminals (windows) where commands run, and you can switch between them or manage them independently.

Installation

Ubuntu / Debian:

sudo apt update
sudo apt install screen -y

CentOS / RHEL / AlmaLinux / Rocky:

sudo yum install screen -y
# или
sudo dnf install screen -y

Basic usage

  1. Start a new session:
screen

You’ll see either a command prompt or a welcome screen (press Space or Enter).

  1. Run your command (e.g., top, htop, python3 script.py, etc.).
  2. Detach from the session (without killing it):
Ctrl + a, then d

You’ll see: [detached from ...]

  1. Reattach later:
screen -r

If you have multiple sessions — list them first:

screen -ls

Example output:

There are screens on:
        1234.pts-0.server    (Detached)
        5678.job1            (Detached)
2 Sockets in /var/run/screen/S-root.

Reattach to a specific one:

screen -r 1234

or by name:

screen -r job1

Useful commands inside Screen

  • Create a new window (inside a session): Ctrl + a, then c
  • Switch between windows: Ctrl + a, then window number (0–9) or Ctrl + a, then " (list of windows)
  • Rename the current window: Ctrl + a, then A → type new name
  • Close the current window: Ctrl + a, then k → confirm with y
  • Quit the entire Screen session: Ctrl + a, then : → type quit → Enter
  • Exit copy mode (if you entered scroll mode): Esc or q

Scrolling output (copy mode)

If command output scrolls off-screen:

  1. Press Ctrl + a, then [ — enter copy mode.
  2. Use arrow keys, Page Up/Down, or vi-style (h,j,k,l) to scroll.
  3. Press Esc or q to exit.

Customizing Screen (~/.screenrc):

Create or edit ~/.screenrc:

Example useful config:

# Disable welcome message
startup_message off

# Always show status bar at the bottom
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}]'

# Auto-create windows on startup
screen -t Main
screen -t Logs
chdir /var/log
screen -t Backup

After saving, new sessions will have a nice status bar and pre-created windows.

Useful tips

  • If a session hangs — reattach with multiuser mode:
screen -x
  • Auto-start Screen on SSH login — add to ~/.bashrc:
if [ -z "$STY" ]; then screen -x || screen -S main; fi
  • Screen is great for long-running processes (OS updates, compilation, big data parsing, bots, etc.).

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us