Skip to content
DBDeependra Bhatta~/notes
Linux#cheat-sheet · #ssh · #linux · #tmux

tmux Cheat Sheet: Sessions, Windows, Panes and Copy Mode

A tmux reference for remote work: sessions that survive SSH drops, windows, split panes, copy mode, synchronized panes, and a minimal tmux.conf.

· updated · 5 min read
ON THIS PAGE

A dropped SSH connection usually kills the processes started in that shell, including a half-finished package upgrade or a migration. tmux, a terminal multiplexer, keeps sessions running on the server after you disconnect and splits one terminal into windows and panes, so a log tail can run beside your working shell. The tables below cover the commands and shortcuts needed for daily remote work.

Every shortcut starts with the prefix Ctrl+b: press Ctrl+b, release it, then press the key. Ctrl+b d means "prefix, then d".

Sessions

A session is a group of windows that lives on the server until you kill it.

Command or shortcutWhat it does
tmuxStarts a new session
tmux new -s nameStarts a new session called name
tmux lsLists sessions
tmux attach (or tmux a)Attaches to the most recent session
tmux a -t nameAttaches to the session name
Ctrl+b d (or tmux detach)Detaches; the session keeps running
Ctrl+b sPicks a session from a list
Ctrl+b $Renames the current session
tmux kill-session -t nameEnds a session
tmux kill-serverEnds all sessions

A typical workflow on a server:

terminal
$ ssh user@server
$ tmux new -s deploy
$ tmux a -t deploy

Start the long-running job inside the deploy session and detach with Ctrl+b d, or lose the connection. After reconnecting over SSH, tmux a -t deploy returns to the job, still running.

Windows

A window works like a browser tab inside a session.

ShortcutWhat it does
Ctrl+b cCreates a window
Ctrl+b ,Renames the current window
Ctrl+b wPicks a window from a list
Ctrl+b n / Ctrl+b pNext / previous window
Ctrl+b 0 to Ctrl+b 9Goes to window number 0 to 9
Ctrl+b &Closes the current window (asks first)

Panes

Panes divide one window into several terminals.

ShortcutWhat it does
Ctrl+b %Splits into left and right panes
Ctrl+b "Splits into top and bottom panes
Ctrl+b oMoves to the next pane (arrow keys also work)
Ctrl+b zZooms the current pane to full size; press again to restore
Ctrl+b { / Ctrl+b }Swaps the pane with the previous / next one
Ctrl+b SpaceCycles through layouts
Ctrl+b xCloses the current pane (asks first)

Copy mode

Copy mode scrolls back through output and copies text without a mouse.

ShortcutWhat it does
Ctrl+b [Enters copy mode
Ctrl+b PgUpEnters copy mode and scrolls up one page
PgUp / PgDnScrolls a page up / down
Ctrl+b ]Pastes the last copied text

The keys to select and copy depend on the mode-keys option. tmux uses emacs-style keys by default, and switches to vi-style keys if your EDITOR or VISUAL variable contains vi.

Actionemacs keys (default)vi keys
Start selectionCtrl+SpaceSpace
Copy selection and exitAlt+wEnter
Exit copy modeq or Escq

To always use vi keys, add setw -g mode-keys vi to your config.

Useful options

Run these from a shell inside tmux, or type them after Ctrl+b : (the tmux command prompt) without the word tmux.

CommandWhat it does
tmux setw synchronize-panes onSends what you type to every pane in the window, useful for running the same command on several servers
tmux setw synchronize-panes offTurns that off again
tmux set -g mouse onLets you click panes, resize them and scroll with the mouse
tmux set -g history-limit 10000Keeps 10,000 lines of scrollback (only for windows created after the change)
tmux source-file ~/.tmux.confReloads the config file
Ctrl+b ?Lists every key binding

To keep these settings, put them in ~/.tmux.conf:

SH.tmux.conf
~.tmux.conf
set -g mouse on
set -g history-limit 10000
setw -g mode-keys vi

Key takeaways

  • Every shortcut starts with the prefix Ctrl+b.
  • Start work on a server inside a named session (tmux new -s name) so it survives SSH drops; reattach with tmux a -t name.
  • % and " split panes, z zooms one, c makes a new window.
  • Copy-mode keys depend on mode-keys; set vi in ~/.tmux.conf if you prefer vi keys.

The tmux wiki on GitHub is the official documentation.