You start a long upgrade over SSH. Twenty minutes in, your laptop sleeps, the wifi changes, or the connection simply dies. The remote shell is killed, and every process it owned dies with it — halfway through a package upgrade, which is the worst possible moment.

A terminal multiplexer fixes this completely. Your shell runs inside a session that belongs to the server, not to your connection. Drop the connection and the session keeps running; reconnect and reattach exactly where you left off.

Of everything in this section, this is the tool that most changes how you work on remote machines. It is also the one people put off learning longest.

The short verdict

Learn tmux. It is actively developed, its splitting and scripting are better, and it is what nearly everyone else uses now.

Know enough screen to reattach a session — three commands’ worth — because it is preinstalled on many older systems where tmux is not, and because someone else’s abandoned screen session is a thing you will eventually need to get into.

Use one of them for anything long-running over SSH. Which one matters far less than the habit.

What you get

screentmux
Survives a dropped connectionYesYes
Multiple windowsYesYes
Split panesHorizontal only, awkwardBoth directions, easily
Rename and organise windowsBasicGood
Status barMinimalConfigurable
Scripting a layoutPainfulStraightforward
Share a session with a colleagueYesYes
Actively developedBarelyYes
PreinstalledOftenSometimes
Default prefix keyCtrl+aCtrl+b

The row that decides it for most people is scripting a layout. Being able to run one command that opens a session with logs in one pane, a shell in another and a monitor in a third — the same way every time — is worth more than any individual feature.

Installing

sudo apt install tmux        # Debian, Ubuntu
sudo dnf install tmux        # Fedora, RHEL, Rocky, Alma
sudo pacman -S tmux          # Arch

Install it on every server you administer, at the same time you do the rest of the first-hour setup in securing a new server. It weighs almost nothing and the first time it saves an interrupted upgrade it has paid for itself.

The prefix key

Everything in tmux is Ctrl+b, released, then a key. That two-step is the thing that feels strange for a day and then disappears.

It exists because tmux has to pass every other keystroke through to the program you are running. Reserving one prefix means Ctrl+c, Ctrl+r and everything else still reach your shell normally.

Below, prefix means “press Ctrl+b, let go, then press the key”.

The five commands that matter

You can get the entire benefit of tmux from these. Everything else is refinement.

# Start a named session
tmux new -s upgrade

# Detach and leave it running:  prefix, then d

# What is running?
tmux ls

# Reattach
tmux attach -t upgrade

# Attach to whatever is there, or create it if not
tmux new -A -s work

Name your sessions. tmux new -s upgrade costs four extra characters and means that in a week you can tell what the three detached sessions on that server are. Unnamed sessions get numbers, and numbers tell you nothing.

tmux new -A -s work is the one to build a habit around: attach if it exists, create it if it does not. It behaves correctly whether you are starting fresh or coming back, so it is the right thing to type every time.

Windows and panes

A session contains windows (like browser tabs), and a window contains panes (splits of the screen).

KeysDoes
prefix dDetach — the one to remember first
prefix cNew window
prefix n / pNext / previous window
prefix 09Jump to a window by number
prefix ,Rename the current window
prefix %Split left/right
prefix "Split top/bottom
prefix arrowMove between panes
prefix zZoom a pane full-screen, and back
prefix xClose the current pane
prefix [Scroll back through output (q to exit)
prefix ?Every binding

Two of those are worth singling out. prefix z temporarily expands one pane to the full window — invaluable when you have split the screen four ways and now need to read something properly. Press it again to restore the layout.

prefix [ catches everyone out. Inside tmux, your mouse wheel and PageUp do not scroll the terminal’s own history — tmux owns the screen. prefix [ enters copy mode, where arrows and PageUp work, and q leaves it. Without this, tmux feels broken the first time you try to look at something that scrolled past.

Configuration worth doing

tmux is usable unconfigured. Four lines in ~/.tmux.conf remove most of the friction:

# Mouse support: click panes, scroll naturally, drag borders
set -g mouse on

# Start numbering at 1 - matches the keyboard
set -g base-index 1
setw -g pane-base-index 1

# A scrollback worth having
set -g history-limit 50000

# Reload this file with: prefix r
bind r source-file ~/.tmux.conf \; display "Reloaded"

set -g mouse on is the single highest-value line. Scrolling works as you expect, clicking a pane focuses it, and dragging a border resizes it — which removes most of the reasons beginners give up on tmux.

Many people also remap the prefix to Ctrl+a, matching screen and being easier to reach:

unbind C-b
set -g prefix C-a
bind C-a send-prefix

Worth knowing the trade-off before you do: Ctrl+a is also “jump to start of line” in bash and in readline generally. The send-prefix line lets you get it back by pressing it twice, but it is a real cost. If you are starting fresh, staying on Ctrl+b avoids the conflict entirely.

Scripting a layout

This is where tmux clearly beats screen. A few lines produce the same working environment every time:

#!/bin/bash
# Set up a monitoring session on a web server

tmux new-session -d -s monitor
tmux send-keys -t monitor 'sudo journalctl -u nginx -f' C-m

tmux split-window -h -t monitor
tmux send-keys -t monitor 'htop' C-m

tmux split-window -v -t monitor
tmux send-keys -t monitor 'sudo tail -f /var/log/nginx/error.log' C-m

tmux attach -t monitor

Save that as ~/.local/bin/monitor, make it executable, and one word gives you a full dashboard. C-m is Enter. See reading Linux logs for what to put in the panes and htop vs top for the middle one.

Enough screen to get by

You will meet screen on older servers and in other people’s abandoned sessions. Its prefix is Ctrl+a.

# Start named
screen -S upgrade

# Detach:  Ctrl+a  then  d

# List sessions
screen -ls

# Reattach
screen -r upgrade

# Steal a session that is still attached elsewhere
# (e.g. attached to a connection that has since died)
screen -dr upgrade

screen -dr is the one worth remembering. A session left attached to a connection that no longer exists refuses a plain -r; -dr detaches it from the ghost and gives it to you. The tmux equivalent is tmux attach -d -t name.

Taskscreentmux
Start namedscreen -S nametmux new -s name
DetachCtrl+a dCtrl+b d
Listscreen -lstmux ls
Reattachscreen -r nametmux attach -t name
Force reattachscreen -dr nametmux attach -d -t name
New windowCtrl+a cCtrl+b c
Kill sessionCtrl+a ktmux kill-session -t name

Where screen is still the right answer

  • It is already there and tmux is not. Older RHEL and CentOS systems, appliances, embedded devices. The multiplexer you have beats the one you would have to install.
  • Serial console access. screen /dev/ttyUSB0 115200 is the standard way to talk to a switch, router or embedded board over serial, and tmux does not do this at all. On a network engineer’s machine that alone justifies keeping it.
  • Attaching to a session someone else started. If a colleague left work running in screen, you need screen.

The serial console case is the genuinely non-replaceable one. Everything else is availability.

And if you have neither

On a locked-down machine with no multiplexer, nohup at least stops a long job dying with your connection:

nohup ./long-import.sh > import.log 2>&1 &

# Then watch it
tail -f import.log

It is a poor substitute — you cannot interact with the job, only read its output — but it is far better than losing a database import halfway through. If a job has already started in the foreground, Ctrl+z then disown -h %1 can sometimes rescue it.

Quick reference

You wantDo this
Start or resume a sessiontmux new -A -s work
Leave it runningprefix d
See what is runningtmux ls
Come backtmux attach -t work
Take over a stuck sessiontmux attach -d -t work
Split vertically / horizontallyprefix % / prefix "
Focus one pane full-screenprefix z
Scroll backprefix [, then q
Turn on the mouseset -g mouse on
Talk to a serial consolescreen /dev/ttyUSB0 115200

Related reading