Software & OS

tmux Cheat Sheet: Sessions, Windows, Panes and Shortcuts

tmux keeps terminal sessions running on a machine after you disconnect and lets you split one terminal into windows and panes. Every shortcut starts with the prefix Ctrl+b: press it, release, then press the command key, so Ctrl+b d detaches and tmux attach brings you back.

tmux new -s work      # start a session named "work"
# ...Ctrl+b d to detach...
tmux ls               # list sessions
tmux attach -t work   # reattach

The key bindings below are the defaults, checked against tmux list-keys on tmux 3.2a and the tmux manual page. Install tmux with sudo apt install tmux (Debian, Ubuntu), sudo dnf install tmux (Fedora) or brew install tmux (macOS). On Windows, run it inside WSL.

Sessions: start, detach, reattach

A session is a set of windows that keeps running in the background. This is the main reason people use tmux: start a long job over SSH, detach, close your laptop, and reattach later to find it still running.

Command or keysWhat it does
tmuxStart a new unnamed session
tmux new -s nameStart a session called name
tmux lsList sessions (short for list-sessions)
tmux attachAttach to the most recent session
tmux attach -t nameAttach to a specific session
tmux kill-session -t nameEnd a session and everything in it
tmux kill-serverEnd all sessions
Ctrl+b dDetach from the current session
Ctrl+b sPick a session from an interactive list
Ctrl+b $Rename the current session

Example output of tmux ls with two sessions:

demo: 1 windows (created Mon Oct 26 13:50:17 2026)
work: 1 windows (created Mon Oct 26 13:50:17 2026)

The error messages you will meet are plain. When nothing is running, tmux 3.2a prints no server running on /tmp/tmux-1000/default or error connecting to /tmp/tmux-1000/default (No such file or directory) (the number is your user ID), and can't find session: name when the name is wrong. Run tmux ls to see the real names.

Windows: tabs inside a session

A window fills the whole terminal, like a browser tab. The status bar at the bottom lists them, with an asterisk on the current one.

KeysWhat it does
Ctrl+b cCreate a new window
Ctrl+b n / Ctrl+b pNext / previous window
Ctrl+b 0 to 9Go to window 0 to 9
Ctrl+b lGo to the last window you used
Ctrl+b wChoose a window from a list
Ctrl+b ,Rename the current window
Ctrl+b &Close the current window (asks to confirm)
Ctrl+b 'Prompt for a window number to jump to

Windows are numbered from 0 by default. If you'd rather start at 1, so the numbers match the keyboard, add set -g base-index 1 to your config.

Panes: split the screen

Panes divide one window into several terminals side by side.

KeysWhat it does
Ctrl+b %Split into left and right panes
Ctrl+b "Split into top and bottom panes
Ctrl+b arrow keyMove to the pane in that direction
Ctrl+b oGo to the next pane
Ctrl+b ;Go to the previously active pane
Ctrl+b zZoom the current pane to full window, and back
Ctrl+b xClose the current pane (asks to confirm)
Ctrl+b !Move the current pane into its own window
Ctrl+b { / Ctrl+b }Swap with the previous / next pane
Ctrl+b SpaceCycle through preset layouts
Ctrl+b qShow pane numbers briefly

The two split keys are easy to mix up. % makes a vertical divider (panes side by side); " makes a horizontal divider (panes stacked). Typing exit in a pane closes it too.

Scrolling and copying text

Your terminal's scroll bar usually doesn't work inside tmux, because tmux redraws the screen itself. Use copy mode instead:

  1. Press Ctrl+b [ to enter copy mode. Output in the pane freezes.
  2. Scroll with the arrow keys or Page Up and Page Down.
  3. To copy (with the default emacs-style keys): move to the start, press Ctrl+Space, move to the end, press Alt+w. That copies the selection and leaves copy mode.
  4. Press Ctrl+b ] to paste the copied text. To leave copy mode without copying, press q.

The tmux wiki notes that copy mode uses emacs-style keys unless the VISUAL or EDITOR environment variable contains "vi" when the server starts, or you set set -g mode-keys vi. With vi keys, page up and down with Ctrl+b and Ctrl+f, start a selection with Space and copy with Enter.

tmux keeps 2,000 lines of history per pane by default (tmux show -g history-limit printed history-limit 2000 on tmux 3.2a). Raise it in your config if long build logs scroll out of reach.

Other useful keys

KeysWhat it does
Ctrl+b ?List every key binding (press q to close)
Ctrl+b :Open the tmux command prompt
Ctrl+b tShow a big clock
Ctrl+b Ctrl+bSend a literal Ctrl+b to the program in the pane

A starter ~/.tmux.conf

tmux reads ~/.tmux.conf when the server starts. A short config that fixes the most common complaints:

# Mouse: click to select panes, drag borders to resize, wheel to scroll
set -g mouse on

# Number windows and panes from 1
set -g base-index 1
setw -g pane-base-index 1

# Keep more scrollback
set -g history-limit 10000

# Optional: use Ctrl+a as the prefix instead of Ctrl+b
# set -g prefix C-a
# unbind C-b
# bind C-a send-prefix

The mouse option is off by default; with it on, tmux "captures the mouse and allows mouse events to be bound as key bindings", which is what makes clicking and wheel scrolling work. To apply changes without restarting, open the command prompt with Ctrl+b : and run source-file ~/.tmux.conf.

The prefix change is the most common customisation, because Ctrl+a is easier to reach. The three lines come straight from the tmux wiki: set the new prefix, unbind the old one, and bind the new key to send-prefix so pressing it twice still sends it to the program inside. The trade-off is that Ctrl+a is also the shell's "go to start of line" shortcut, which then needs two presses.

A typical SSH workflow

ssh alex@server
tmux new -s deploy
./long-running-migration.sh
# Ctrl+b d, then close the laptop

# later, from anywhere
ssh alex@server
tmux attach -t deploy

If the SSH connection drops instead of you detaching, the result is the same: the session keeps running and you reattach. To check on what's running inside without attaching, ps works as usual from another shell (see ps aux explained). A session does end if the server reboots or someone runs tmux kill-server.

If tmux won't attach

sessions should be nested with care, unset $TMUX to force means you are already inside tmux and tried to start or attach another session from within it. Detach first, or switch sessions with Ctrl+b s. If tmux ls shows nothing after an SSH reconnect, check you are on the same machine and the same user account: each user has their own tmux server, and sessions started with sudo belong to root.

Frequently asked questions

How do I scroll up in tmux?
Press Ctrl+b then [ to enter copy mode, then use the arrow keys or Page Up and Page Down. Press q to leave. If you prefer the mouse wheel, add set -g mouse on to ~/.tmux.conf and reload it. tmux keeps 2,000 lines of history per pane by default; raise it with set -g history-limit 10000.
Do tmux sessions survive closing the terminal or an SSH disconnect?
Yes. The session lives in the tmux server process on that machine, not in your terminal window. Closing the window or losing the SSH connection only detaches the client. Run tmux attach after reconnecting. Sessions do not survive a reboot of the machine running tmux.
How do I kill all tmux sessions?
Run tmux kill-server. It ends every session and every program running inside them, so save your work first. To end one session only, use tmux kill-session -t name.
Can I use tmux on Windows?
Not natively in Command Prompt or PowerShell. Install it inside WSL (for example sudo apt install tmux in Ubuntu) and run it there, or run it on a Linux server you connect to over SSH, which is where it is most useful.

Sources