Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

tmux

Keep terminal sessions alive on a server, split the screen into panes, and come back after the SSH connection drops.

Level
DevOps tool
Group
Shell and help
Needs root
No
Package
tmux

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 -s NAME
Start a new named session.
attach -t NAME / a
Attach to a session (the last one with a).
ls
List sessions.
kill-session -t NAME
End a session.
new-window / split-window -h / -v
New window / split left-right or top-bottom.
send-keys -t TARGET '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)

d
Detach (the session keeps running).
c / n / p / 0-9
New window / next / previous / go to window N.
% / "
Split the pane left-right / top-bottom.
arrow keys / o
Move to another pane.
z
Zoom the pane full screen and back.
x / &
Close the pane / the window.
[
Scroll mode (q to leave).
, / $
Rename the window / the session.
s / w
Choose a session / window from a list.
:
Command prompt (for example :setw synchronize-panes on).

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Start a named session for a long job

    tmux new -s upgrade
    sudo dnf -y upgrade

    Press Ctrl+b d to detach. The upgrade keeps running.

  2. 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 upgrade
  3. 3Attach or create in one command

    tmux new -A -s main
  4. 4Run a job in a detached session from a script

    tmux new -d -s backup 'restic backup /srv && echo done > /tmp/backup.ok'
  5. 5Split for logs and a shell side by side

    tmux new -s debug \; split-window -h 'journalctl -u shop -f' \; select-pane -L
  6. 6Type 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 on
  7. 7Send keys into a running session

    tmux send-keys -t upgrade 'tail -n 20 /var/log/dnf.log' Enter
  8. 8Save the scroll-back of a pane to a file

    tmux capture-pane -p -S -3000 -t upgrade > upgrade.log

    To scroll by hand: Ctrl+b [ , then arrows or PgUp; q to leave.

  9. 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.conf
  10. 10End a session

    tmux kill-session -t upgrade

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.
  • screen is the older tool with the same idea (screen -S name, screen -r).

Exit codes

0OK.
1Error (for example no such session).