Using tmux
tmux is a terminal multiplexer — it lets you run multiple terminal sessions inside a single window, detach from them while they keep running, and reattach from any other terminal. It is indispensable for remote work over SSH: your session survives connection drops, you can leave long-running processes unattended, and you can organize your work across multiple windows and panes without opening a pile of separate terminal tabs.
This guide uses Ctrl-t as the prefix key (chord key). The default is Ctrl-b, but Ctrl-t is easier to reach and less likely to conflict with terminal line editing. The configuration section at the end shows how to set this up.
Core Concepts
| Term | Meaning |
|---|---|
| Session | A collection of windows, persists after you detach |
| Window | A single full-screen tab inside a session |
| Pane | A subdivision of a window; multiple panes share the screen |
| Prefix | A key chord (Ctrl-t) you press before every tmux command |
The workflow is: press the prefix, release it, then press the command key. For example, Ctrl-t c means: hold Ctrl and press t, release both, then press c.
Starting tmux
tmux # start a new unnamed session
tmux new -s work # start a new session named "work"
tmux attach # attach to the most recent session
tmux attach -t work # attach to the session named "work"
tmux ls # list all running sessions
Sessions
| Command | Action |
|---|---|
Ctrl-t d |
Detach from the current session (session keeps running) |
Ctrl-t $ |
Rename the current session |
Ctrl-t s |
Show a list of sessions and switch between them |
Ctrl-t ( |
Switch to the previous session |
Ctrl-t ) |
Switch to the next session |
Sessions are persistent. When you detach, every window, pane, and running process keeps going. SSH connection dropped? Reconnect and tmux attach.
Windows
| Command | Action |
|---|---|
Ctrl-t c |
Create a new window |
Ctrl-t , |
Rename the current window |
Ctrl-t w |
List windows and switch interactively |
Ctrl-t n |
Next window |
Ctrl-t p |
Previous window |
Ctrl-t 0–9 |
Switch to window by number |
Ctrl-t & |
Kill the current window (prompts for confirmation) |
Ctrl-t l |
Switch to the last (most recently used) window |
Windows are displayed in the status bar at the bottom of the screen. The current window is marked with *.
Panes
Panes split a single window into multiple independent terminals.
| Command | Action |
|---|---|
Ctrl-t % |
Split the current pane vertically (left/right) |
Ctrl-t " |
Split the current pane horizontally (top/bottom) |
Ctrl-t arrow |
Move to the pane in that direction |
Ctrl-t o |
Cycle to the next pane |
Ctrl-t ; |
Switch to the last active pane |
Ctrl-t z |
Zoom the current pane to full screen (toggle) |
Ctrl-t x |
Kill the current pane (prompts for confirmation) |
Ctrl-t ! |
Break the current pane out into its own window |
Ctrl-t { |
Swap the current pane with the previous |
Ctrl-t } |
Swap the current pane with the next |
Ctrl-t q |
Show pane numbers (press a number to jump to that pane) |
Ctrl-t Space |
Cycle through preset pane layouts |
Resizing Panes
Hold the prefix and then use the arrow keys, or use the resize-pane command:
| Command | Action |
|---|---|
Ctrl-t Ctrl-arrow |
Resize pane by 1 cell in that direction |
Ctrl-t Alt-arrow |
Resize pane by 5 cells in that direction |
Copy Mode
Copy mode lets you scroll back through terminal history and copy text without a mouse.
| Command | Action |
|---|---|
Ctrl-t [ |
Enter copy mode |
Arrow keys / PgUp / PgDn |
Scroll through history |
q or Esc |
Exit copy mode |
Space |
Start selection (vi mode) |
Enter |
Copy selection and exit copy mode |
Ctrl-t ] |
Paste the copied text |
To use vi-style key bindings in copy mode (recommended), add setw -g mode-keys vi to your config (included in the example below).
In vi copy mode:
| Key | Action |
|---|---|
h j k l |
Move cursor |
v |
Begin selection |
y |
Yank (copy) selection |
/ |
Search forward |
? |
Search backward |
n / N |
Next/previous search match |
g / G |
Jump to top / bottom of history |
Miscellaneous Commands
| Command | Action |
|---|---|
Ctrl-t ? |
Show all key bindings |
Ctrl-t : |
Open the tmux command prompt |
Ctrl-t t |
Show a clock in the current pane |
Ctrl-t ~ |
Show previous tmux messages |
Ctrl-t i |
Show information about the current window |
Useful Command Prompt Commands
Press Ctrl-t : and type:
new-window -n logs # create a window named "logs"
split-window -h # split horizontally
kill-session # kill the current session
setw synchronize-panes on # send keystrokes to all panes simultaneously
setw synchronize-panes off # stop synchronizing panes
synchronize-panes is useful for running the same command on multiple servers at once — split into panes, SSH to a different host in each, then turn on sync.
Configuration
tmux is configured in ~/.tmux.conf. Changes take effect on the next new session, or immediately with Ctrl-t : then source-file ~/.tmux.conf.
# ~/.tmux.conf
# Change the prefix key from Ctrl-b to Ctrl-t
unbind C-b
set -g prefix C-t
bind C-t send-prefix # Ctrl-t Ctrl-t sends a literal Ctrl-t to the terminal
# Sane split key bindings (same keys as above, but easier to remember)
bind | split-window -h # Ctrl-t | for vertical split
bind - split-window -v # Ctrl-t - for horizontal split
unbind '"'
unbind %
# Move between panes with vim-style keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Resize panes with vim-style keys (hold prefix)
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# Use vi keys in copy mode
setw -g mode-keys vi
# Start window and pane numbering at 1 (easier keyboard access)
set -g base-index 1
setw -g pane-base-index 1
# Renumber windows when one is closed
set -g renumber-windows on
# Increase scrollback buffer
set -g history-limit 10000
# Enable mouse support (click to select panes/windows, scroll)
set -g mouse on
# 256-color support
set -g default-terminal "screen-256color"
# Faster key repetition (reduces escape key delay)
set -s escape-time 0
# Status bar
set -g status-interval 5
set -g status-left "[#S] "
set -g status-right "%H:%M %d-%b"
After saving, reload without restarting:
tmux source-file ~/.tmux.conf
# or from inside tmux:
# Ctrl-t : source-file ~/.tmux.conf
Common Workflows
Working Remotely Over SSH
ssh user@server
tmux new -s main # start a session
# ... do work ...
# connection drops
ssh user@server
tmux attach -t main # pick up exactly where you left off
Organizing a Development Environment
tmux new -s dev
# Window 1: editor
Ctrl-t , # rename to "editor"
vim .
# Window 2: server
Ctrl-t c
Ctrl-t , # rename to "server"
python -m http.server
# Window 3: logs + shell
Ctrl-t c
Ctrl-t , # rename to "logs"
Ctrl-t " # split horizontally
tail -f /var/log/syslog # top pane
Ctrl-t o # move to bottom pane
# bottom pane: general shell
Running a Command on Multiple Hosts
tmux new -s deploy
Ctrl-t " # split: top and bottom panes
Ctrl-t % # split top pane left/right
# now 3 panes: SSH into a different host in each one
Ctrl-t : setw synchronize-panes on # type in all panes at once
sudo systemctl restart nginx
Ctrl-t : setw synchronize-panes off
Quick Reference Card
Sessions
tmux new -s <name> new session
tmux attach -t <name> attach to session
tmux ls list sessions
Ctrl-t d detach
Ctrl-t s switch session
Ctrl-t $ rename session
Windows
Ctrl-t c new window
Ctrl-t , rename window
Ctrl-t n / p next / prev window
Ctrl-t 0-9 jump to window
Ctrl-t w list windows
Ctrl-t & kill window
Panes
Ctrl-t % split vertical
Ctrl-t " split horizontal
Ctrl-t arrow move to pane
Ctrl-t z zoom/unzoom pane
Ctrl-t x kill pane
Ctrl-t q show pane numbers
Copy Mode
Ctrl-t [ enter copy mode
v / y select / yank (vi mode)
Ctrl-t ] paste
Other
Ctrl-t ? show key bindings
Ctrl-t : command prompt