Why use tmux and screen on a VDS
An SSH session drops when the connection is interrupted, a router reboots, or Wi-Fi disconnects. Every process running in that terminal receives a HUP signal and gets killed. If that process is apt upgrade, a kernel build, or a long database backup, the work is lost halfway through. tmux and screen solve this problem: they start a separate terminal session on the server that keeps running independently of the SSH connection. Disconnect, and the session keeps working. Reconnect, and you see the same screen with the same commands still running.
Both tools solve the same task but are built differently. Let's cover installation, basic commands, and how the tools differ.
Installing tmux and screen
Both packages are available in the standard repositories of most distributions.
apt update
apt install -y tmux screen
For CentOS, Rocky Linux, and AlmaLinux:
dnf install -y tmux screen
Check the version with tmux -V and screen --version. For heavy tasks like migrating a database or building a package by hand, use these tools right after your first SSH connection to the server, before starting the work.
Basic tmux commands
tmux works with sessions, windows, and panes. A session can be named, which is convenient when you run several of them.
| Command | Action |
|---|---|
tmux new -s backup | create a session named backup |
tmux ls | list active sessions |
tmux attach -t backup | attach to the backup session |
Ctrl+b d | detach from the session |
Ctrl+b % | split the window into panes vertically |
Ctrl+b " | split the window horizontally |
tmux kill-session -t backup | terminate the session |
The key combination starts with the Ctrl+b prefix, followed by a separate command key. This is what sets tmux apart from screen, where the prefix is Ctrl+a.
Basic screen commands
screen predates tmux and is built more simply: one window equals one terminal, with no built-in pane splitting in the base version.
screen -S backup
screen -ls
screen -r backup
Detach from a session with Ctrl+a d, create a new window inside a session with Ctrl+a c, and switch between windows with Ctrl+a n (next) and Ctrl+a p (previous). Sometimes, after a dropped connection, a session stays in the "Attached" state, and reconnecting with screen -r returns an error. Run screen -d -r backup instead, which forcibly detaches the old connection.
How tmux differs from screen
The difference goes beyond keyboard shortcuts.
- tmux can split a window into panes without extra packages; screen needs a module or a newer build for that.
- tmux supports a configuration file at
~/.tmux.confwith flexible status bar and color scheme settings. - screen runs on almost any Unix server without installation — it is often already present by default.
- tmux is developed more actively and usually restores its layout faster after an SSH disconnect.
For everyday work on a VDS, most administrators choose tmux for its panes and convenient configuration. screen remains a good option for minimal systems where you don't want extra packages installed.
What to do after an SSH disconnect
If the connection drops on its own, not through detach, the tmux or screen session stays running in the background, and its processes keep going. Once the connection is back, simply reconnect over SSH and run tmux attach or screen -r. To avoid mixing up sessions, give them clear names right away, for example tmux new -s deploy instead of an unnamed session with a number.
For long background tasks with no interactive output, a real daemon managed by systemd fits better — for recurring jobs, see creating a unit file for an auto-starting service or setting up the cron scheduler. tmux and screen are meant for interactive work: migrations, package installs, and real-time diagnostics.
Summary: what to remember
- tmux and screen keep a terminal session running on the server when the SSH connection drops.
- Install with
apt install -y tmux screenordnf install -y tmux screen. - In tmux the prefix is
Ctrl+b; in screen it isCtrl+a. - Name sessions when creating them:
tmux new -s name,screen -S name. - Use systemd or cron for background tasks with no interaction, not tmux.