Mastering GNU Screen

A guide to managing persistent terminal sessions and background processes.

GNU Screen is a powerful terminal multiplexer that allows you to manage multiple virtual sessions within a single SSH connection. Its primary advantage is persistence: you can start a process, disconnect from the server, and reconnect later to find your programs exactly where you left them.

Screen is an essential tool for:

  • Long-running tasks: Software installations, data parsing, backups, or server migrations.
  • Unstable connections: Protecting your work from accidental SSH disconnects.
  • Multi-device workflow: Starting a task at the office and resuming it from home.

Installing Screen

Most Linux distributions include Screen in their official repositories and can be installed with a single command:

Debian / Ubuntu:

sudo apt update
sudo apt install screen

CentOS / Rocky Linux / AlmaLinux / Fedora:

sudo dnf install screen
# or
sudo yum install screen

Essential Screen commands

  1. Start a new named session
screen -S session_name
  1. Keyboard shortcuts
Action Key Combination Description
Detach from Session Ctrl + A then D Disconnect while keeping processes running.
Create New Window Ctrl + A then C Open a new window within the current session.
Next Window Ctrl + A then N Switch to the next available window.
Previous Window Ctrl + A then P Switch to the previous available window.
Window List Ctrl + A then " Display a list of all windows (or input a number).
Kill Current Window Ctrl + A then K Terminate the current window (use with caution!).
Horizontal Split Ctrl + A then S Split the display into two horizontal regions.
Quit Screen Ctrl + A then Ctrl + \ Kill all windows and terminate the entire session.
  1. List active sessions
screen -ls
  1. Reattach to a session
screen -r session_name

If a session is already attached elsewhere, use the following to force a reattach:

screen -rd session_name

Pro tips

  • Stay detached: To keep your scripts running after closing your SSH client, always remember to detach using Ctrl + A then D.
  • Use cases: Screen is the perfect environment for running game servers, bots, and heavy background scripts that shouldn't be interrupted.
  • Next steps: If you enjoy using Screen, consider exploring Tmux, a modern alternative with even more advanced window management features.

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