What it does
tmux is a terminal multiplexer. A session holds windows (like tabs), and a window can be split into panes. The session runs on the server: when your SSH connection breaks, the long job (a migration, an upgrade, a backup) keeps running and you attach again later.
All keys start with the prefix Ctrl+b, then one key: Ctrl+b d detaches, Ctrl+b % splits.
How to write it
tmux [COMMAND [OPTIONS]]Main parts
Commands
new-sNAME- Start a new named session.
attach-tNAME/a- Attach to a session (the last one with
a). ls- List sessions.
kill-session-tNAME- End a session.
new-window/split-window-h/-v- New window / split left-right or top-bottom.
send-keys-tTARGET'cmd'Enter- Type into a pane from a script.
source-file~/.tmux.conf- Load the config again.
Options 10
Most used
Keys (after Ctrl+b)
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Start a named session for a long job
Press Ctrl+b d to detach. The upgrade keeps running.
2Come back later (also after a new SSH login)
tmux ls upgrade: 1 windows (created Fri Oct 31 09:10:00 2026) tmux attach -t upgrade3Attach or create in one command
tmux new -A -s main4Run a job in a detached session from a script
tmux new -d -s backup 'restic backup /srv && echo done > /tmp/backup.ok'5Split for logs and a shell side by side
tmux new -s debug \; split-window -h 'journalctl -u shop -f' \; select-pane -L6Type the same command on many servers at once
tmux new -s fleet \; split-window 'ssh web2' \; split-window 'ssh web3' \; select-layout even-vertical \; setw synchronize-panes on7Send keys into a running session
tmux send-keys -t upgrade 'tail -n 20 /var/log/dnf.log' Enter8Save the scroll-back of a pane to a file
tmux capture-pane -p -S -3000 -t upgrade > upgrade.logTo scroll by hand: Ctrl+b [ , then arrows or PgUp; q to leave.
9A small ~/.tmux.conf
cat ~/.tmux.conf set -g mouse on set -g history-limit 50000 set -g base-index 1 tmux source-file ~/.tmux.conf10End a session
tmux kill-session -t upgrade
Nothing matches this filter.
Watch out
- A detached session runs as your user with your rights — log out of root shells inside it when done.
- Nested tmux (tmux in tmux over SSH) needs the prefix twice: Ctrl+b Ctrl+b.
Files
~/.tmux.conf- Your settings.
Tips to remember
- Always start long remote jobs (upgrades, data copies) inside tmux.
screenis the older tool with the same idea (screen -S name,screen -r).
Exit codes
0 | OK. |
1 | Error (for example no such session). |