tmux is a terminal multiplexer. It does two things that make server work much less stressful:
- Sessions survive disconnects. Start a long upgrade or migration inside tmux; if your Wi-Fi drops or you close the laptop, it keeps running. Reconnect and pick up exactly where you were.
- Multiple terminals in one. Split the screen into panes — logs in one, a shell in another — and switch between windows like browser tabs.
Install
sudo apt install tmux # Debian/Ubuntu
sudo dnf install tmux # RHEL family
The prefix key
Every tmux shortcut starts with the prefix: Ctrl+b, then release, then press the command key. Written below as C-b.
Sessions
tmux # new session
tmux new -s upgrade # new named session
tmux ls # list sessions
tmux attach -t upgrade # reattach (short: tmux a -t upgrade)
tmux attach # reattach to the most recent
tmux kill-session -t upgrade
Inside tmux:
| Keys | Action |
|---|---|
C-b d |
Detach — leave the session running in the background |
C-b s |
List and switch sessions |
C-b $ |
Rename the session |
The workflow: SSH in → tmux new -s work → run things → C-b d or just lose the connection → SSH in again → tmux a -t work.
Windows (tabs)
| Keys | Action |
|---|---|
C-b c |
New window |
C-b n / C-b p |
Next / previous window |
C-b 0…9 |
Go to window number |
C-b , |
Rename window |
C-b w |
Choose from a list |
C-b & |
Close window (confirm) |
Panes (splits)
| Keys | Action |
|---|---|
C-b % |
Split left/right |
C-b " |
Split top/bottom |
C-b + arrow |
Move between panes |
C-b z |
Zoom the current pane full-screen (toggle) |
C-b x |
Close pane |
C-b space |
Cycle layouts |
C-b { / C-b } |
Swap panes |
C-b + hold arrow |
Resize (with C-b then Ctrl+arrow in default config) |
Typing exit in a pane closes it, too.
Scrolling and copying
tmux has its own scrollback. Press C-b [ to enter copy mode: scroll with arrows or Page Up/Down, search with / (or ?), press q to leave. To copy: in copy mode press Space to start selecting, move, Enter to copy; C-b ] pastes.
With mouse mode on (see config), you can scroll with the wheel and click panes.
A practical ~/.tmux.conf
# Mouse support: click panes, scroll, resize
set -g mouse on
# Bigger scrollback
set -g history-limit 50000
# Windows and panes start at 1
set -g base-index 1
setw -g pane-base-index 1
# Intuitive splits that keep the current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Reload config
bind r source-file ~/.tmux.conf \; display "Reloaded"
# Better colours
set -g default-terminal "tmux-256color"
Reload inside tmux with C-b : and source-file ~/.tmux.conf (or C-b r after the first load).
Many people also remap the prefix to C-a (as in GNU screen):
unbind C-b
set -g prefix C-a
bind C-a send-prefix
Everyday server workflows
Long-running commands
tmux new -s release
sudo apt full-upgrade # or a database import, rsync, a build…
# C-b d — go home, reconnect later
Watch logs while you work
C-b % # split
journalctl -u nginx -f # right pane
C-b ← # back to the left pane to edit configs
Shared sessions — two admins attaching to the same session see the same screen: useful for pair debugging.
Run a command in a new detached session from a script
tmux new -d -s backup 'rsync -a /data/ backup:/data/; read'
tmux vs screen vs nohup
- screen — older multiplexer, still common; similar idea, different keys.
- nohup — runs one command detached from the terminal, but you can’t reattach to interact.
- systemd services — for things that should run permanently, write a service rather than leaving them in tmux.
Troubleshooting
sessions should be nested with care, unset $TMUX to force— you’re already inside tmux. Detach first, or switch withC-b s.- Colours look wrong — set
default-terminalas above and make sure your local terminal reports 256 colours. - Session gone after reboot — tmux sessions live in memory; plugins like tmux-resurrect can restore layouts, but processes are gone after a reboot.
Quick reference card: C-b d detach · tmux a attach · C-b c new window · C-b % / C-b " split · C-b z zoom · C-b [ scroll.