Guides

tmux cheat sheet: sessions, windows, panes and the keys you actually use

The tmux keys and commands used every day: Ctrl-b bindings for windows and panes, detaching and reattaching a session, copy mode, and a minimal .tmux.conf.

Published ~8 min read
On this page

Short answer: tmux keeps a terminal session running on the server after you disconnect, and lets you split it into multiple windows and panes. Every command below starts with the prefix key, Ctrl-b by default, pressed and released, then the key that follows it; the two are never held down together.

The commands you use every day

Keys (after Ctrl-b)Action
cNew window
n / pNext / previous window
0–9Jump to window number
,Rename the current window
%Split pane vertically (side by side)
"Split pane horizontally (stacked)
arrow keys / oMove to the next pane
zZoom the current pane to full size, press again to undo
dDetach: leave the session running and return to your shell
[Enter copy mode (scroll back, select text)
xKill the current pane (asks to confirm)
&Kill the current window (asks to confirm)
?List every key binding

Sessions: the part that survives a disconnect

A session is what tmux calls the whole thing: its windows, their panes and everything running inside them. It keeps running on the server whether or not a terminal is attached to it, which is the entire point: start a long build, a download or a game server inside tmux over SSH, detach, close your laptop, and it is still running when you reconnect.

CommandAction
tmuxStart a new, unnamed session
tmux new -s nameStart a new session with a name
tmux lsList running sessions
tmux attachAttach to the most recent session
tmux attach -t nameAttach to a session by name
tmux kill-session -t nameKill a session (and everything in it) by name

Inside tmux, the same actions have key bindings: Ctrl-b d detaches, Ctrl-b s opens a visual list of sessions to switch between, and Ctrl-b $ renames the current session.

Windows and panes

A window is a full screen inside the session, shown as a tab-like list at the bottom; a pane is a rectangle the window is split into. Most people run one shell per window and only split panes when they need two things side by side (logs next to a shell, say).

Keys (after Ctrl-b)Action
cNew window
wVisual list of windows to switch between
lLast active window
%Split the current pane vertically
"Split the current pane horizontally
qBriefly show pane numbers
Ctrl + arrow keysResize the current pane
SpaceCycle through the built-in pane layouts
!Break the current pane out into its own window

Scrolling and copying text

tmux does not scroll with the mouse wheel by default the way a normal terminal does: it has its own scrollback buffer, entered with Ctrl-b [ (copy mode). Inside copy mode the arrow keys, Page Up/Page Down and Ctrl-u/Ctrl-d move around; q or Esc leaves it.

KeyAction
Ctrl-b [Enter copy mode
SpaceStart a selection
EnterCopy the selection and exit copy mode
q / EscExit copy mode without copying
Ctrl-b ]Paste the last copied text
/Search forward; n jumps to the next match

Attach and detach, precisely

“Detach” and “attach” are the two sides of the same thing: Ctrl-b d detaches from inside tmux, tmux attach (or tmux attach -t name for a specific one) reattaches from an ordinary shell. Closing the terminal window, losing the SSH connection, or your laptop going to sleep all detach you the same way a crash would: the session keeps running on the server either way. Two people can even attach to the same session at once and both see every keystroke, useful for pairing over SSH.

A typical session
ssh root@203.0.113.10
tmux new -s build          # start a long job in a named session
# ... Ctrl-b d to detach, close the laptop, go home ...

ssh root@203.0.113.10
tmux ls                    # build: 1 windows (created ...)
tmux attach -t build       # back exactly where you left it

tmux vs screen

GNU Screen does the same basic job (a detachable terminal) and predates tmux by two decades. tmux has become the default choice since: panes split more flexibly than screen’s regions, its status line shows more by default, and a scriptable control mode (tmux -CC) lets terminal apps like iTerm2 and Windows Terminal draw tmux panes as native tabs. screen is still preinstalled on more systems out of the box; tmux is one apt install tmux or dnf install tmux away on everything current.

A minimal ~/.tmux.conf

~/.tmux.conf
# Scroll and select with the mouse
set -g mouse on

# Start window and pane numbering at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

# Bigger scrollback buffer (default is 2000 lines)
set -g history-limit 10000

# Reload this file without restarting tmux: Ctrl-b r
bind r source-file ~/.tmux.conf \; display "Reloaded"

Changes to ~/.tmux.conf only apply to new sessions until you reload it: either restart tmux, or use the bind r line above and press Ctrl-b r inside an existing session.

Run a long job inside tmux and an SSH client timeout or a flaky connection (SSH: broken pipe) no longer kills it: the session is still there when you reconnect.

Frequently asked

What is the tmux prefix key?

Ctrl-b by default, pressed and released before the key that follows it, for example Ctrl-b c for a new window. It is not held down together with the next key.

How do I detach from a tmux session without closing it?

Press Ctrl-b, then d. The session and everything running inside it keeps going on the server; reattach later with tmux attach or tmux attach -t name.

How do I scroll up in tmux?

Enter copy mode with Ctrl-b [, then use the arrow keys, Page Up/Page Down or Ctrl-u/Ctrl-d to move through the scrollback. Press q or Esc to leave copy mode. With 'set -g mouse on' in ~/.tmux.conf, the mouse wheel scrolls directly.

What is the difference between tmux and screen?

Both let a terminal session survive a disconnect. tmux has become the default since: more flexible pane splitting, a more informative status line, and a scriptable control mode that terminal apps use to draw tmux panes as native tabs.

Related articles

All guides

client_loop: send disconnect: Broken pipe? Keep idle SSH sessions alive

SSH drops with client_loop: send disconnect: Broken pipe when idle? Set ServerAliveInterval, check NAT timeouts and use tmux so work survives a drop.

How to secure SSH access on a public server

Port 22 gets brute-forced within minutes. Key-only auth plus fail2ban and a firewall removes almost all the risk. The practical, in-order setup.

Initial server setup: the first ten minutes on a new VPS

A repeatable checklist for a fresh Ubuntu or Debian server: non-root user, key-only SSH, firewall, automatic security updates, hostname, timezone and swap.

screen command in Linux: sessions, detach, reattach and scrollback

The screen command in Linux keeps a session running after SSH disconnects: screen -S, Ctrl-a d, screen -ls, screen -r, windows, scrollback and logging.

How to clear the terminal in Linux: clear, Ctrl+L, reset and the scrollback

Clear terminal screens in Linux with clear or Ctrl+L, keep or wipe the scrollback, fix a garbled terminal with reset, and clear bash history properly.

Terraria server hosting on Linux: dedicated server, TShock, tModLoader and port 7777

Terraria server hosting on your own VPS: the 1.4.5.8 dedicated server, serverconfig.txt, TCP 7777, tmux and systemd, TShock on .NET 9, tModLoader.

tmux vs Zellij: which terminal multiplexer for a server?

Zellij vs tmux on a server: installing Zellij from the release binary, its Ctrl-key modes, sessions and resurrection, and when tmux or screen fits better.

Oh My Zsh and Powerlevel10k on a Linux server: install, p10k configure, fonts and plugins

Install zsh, Oh My Zsh and the Powerlevel10k theme on a Linux server over SSH: p10k configure, MesloLGS NF fonts, plugins and how to switch back to bash.