tmux: The Terminal Multiplexer
- tmux: The Terminal Multiplexer
The tool that saves your work when the connection drops
Picture this: you ssh into the course VM, start a long fuzzing run or a gdb session, and your laptop’s Wi-Fi hiccups. The SSH connection dies, your shell gets a SIGHUP, and everything you were running is gone. tmux is the tool that makes that never happen again — and, as a bonus, lets you split one terminal into many.
A terminal multiplexer does two big things: it persists sessions independently of any connection (detach, disconnect, reconnect later, everything still running), and it multiplexes one terminal into multiple windows and panes. For remote work over SSH it is close to essential, which is why the course setup installs and configures it.
This page covers the theory (what tmux is and its client-server model) and the practice (sessions, windows, panes, copy mode, and config), with the operational payoffs called out along the way.
Theory
From SCREEN to tmux
The idea is old. screen (yes, historically written all-caps) pioneered persistent, detachable terminal sessions in the 1980s. tmux is the modern successor: same core idea, but a cleaner client-server design, easier configuration, vertical and horizontal splits, and a scripting interface. Both use a chorded interface — a prefix key combination puts tmux into command mode, then a follow-up key performs an action (the same interaction model as Emacs and VS Code; vim, by contrast, is modal).
The client-server model
This is the key mental model and the source of tmux’s power. tmux is not one program but two roles:
- A server runs in the background. It owns all your sessions and the processes inside them. It keeps running even when nothing is displaying it — this is what survives an SSH disconnect.
- A client is what you see: it attaches to the server and renders a session. You can detach a client (the session keeps running on the server) and attach a new client later — from a different terminal, a different machine, even a different SSH connection.
So “closing the window” doesn’t kill your work; it just detaches a client. The server, and everything in it, keeps humming until you explicitly kill it or the machine reboots.
The session / window / pane hierarchy
tmux organizes terminals in three nested levels — learn this vocabulary and the keybindings make sense:
session ← a named workspace (e.g. "labwork"); survives disconnects
└── window ← like a tab; one full screen, has a number and name
└── pane ← a split of a window; each pane is one shell/program
- A pane holds a single shell or program.
- A window contains one or more panes (a tiled split) and acts like a tab.
- A session contains one or more windows. The server runs one or more sessions.
So you might keep one session per project, with a window for editing, a window split into panes for a program and its debugger, and another window watching logs — all persistent.
Practice
The prefix key
Every tmux command starts with the prefix, by default Ctrl+b (written C-b). Press the prefix, release, then press the command key. Many people rebind the prefix to Ctrl+a (easier to reach, the old screen binding) in their config.
In the tables below, C-b means “press the prefix,” and the second key is the command.
Sessions — the persistence layer
From the shell:
tmux # start a new unnamed session
tmux new -s labwork # start a new NAMED session 'labwork'
tmux ls # list running sessions (on the server)
tmux attach -t labwork # re-attach to a session
tmux attach # attach to the most recent session
tmux kill-session -t labwork # end a session
| Prefix key | Action |
|---|---|
C-b d |
Detach — leave the session running, return to your shell (the killer feature) |
C-b s |
Interactive list of sessions to switch to |
C-b $ |
Rename the current session |
The persistence workflow over SSH: ssh server, tmux new -s work, do things, C-b d to detach (or just lose the connection), and later ssh server; tmux attach -t work — exactly where you left off. This is the process-persistence story done right, far better than nohup/disown for interactive work.
Windows — like tabs
| Prefix key | Action |
|---|---|
C-b c |
Create a new window |
C-b n / C-b p |
Next / previous window |
C-b 0…9 |
Jump to window by number |
C-b , |
Rename the current window |
C-b w |
Interactive window/session tree |
C-b & |
Kill the current window |
Panes — splitting one screen
By default C-b % splits left/right and C-b " splits top/bottom (unintuitive, so many configs rebind these to | and -).
| Prefix key | Action |
|---|---|
C-b % |
Split pane left/right (vertical divider) |
C-b " |
Split pane top/bottom (horizontal divider) |
C-b + arrow |
Move focus between panes |
C-b o |
Cycle to the next pane |
C-b z |
Zoom — toggle the current pane to full screen and back |
C-b x |
Kill the current pane |
C-b { / C-b } |
Swap pane position |
C-b + C-arrow |
Resize the current pane |
C-b Space |
Cycle through preset layouts |
A common debugging layout: source/editor in one pane, the program in a second, and gdb/pwndbg in a third — all visible at once, all in one SSH session.
Copy mode and scrollback
The terminal’s own scrollback doesn’t work normally inside tmux; instead you enter copy mode to scroll, search, and select:
C-b [ enter copy mode (then PgUp/PgDn/arrows to scroll)
C-b ] paste the copied buffer
In copy mode you can search the scrollback (/ forward, ? back with vi keys) and select text to copy into a tmux buffer. Setting setw -g mode-keys vi makes copy-mode navigation use vi bindings.
Configuration: ~/.tmux.conf
tmux is configured in ~/.tmux.conf. A sensible starter:
# Rebind prefix to Ctrl-a (easier than Ctrl-b)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Intuitive split bindings, opening in the current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
set -g mouse on # mouse: select panes, resize, scroll
setw -g mode-keys vi # vi keys in copy mode
set -g base-index 1 # number windows from 1, not 0
set -g history-limit 50000 # bigger scrollback
# Reload config without restarting tmux
bind r source-file ~/.tmux.conf \; display "reloaded"
Reload a changed config from inside tmux with C-b :source-file ~/.tmux.conf (or the C-b r binding above).
Plugins and scripted layouts
The tmux Plugin Manager (tpm) manages plugins; popular ones add a richer status bar (powerline), and tmux-resurrect/tmux-continuum save and restore entire session layouts across reboots. For repeatable layouts, tmuxinator describes a session (windows, panes, commands) in a YAML file so a single command rebuilds your whole working environment.
ℹ️ Because the tmux server is just a process, you can drive it by script:
tmux send-keys -t work:0 "make test" Entertypes into a pane from outside, andtmux new-session -dstarts a detached session. This is how dashboards and automated lab setups are built.
Why it matters here
- Resilience over SSH. Long-running labs, captures, and debugging survive a dropped SSH connection — start everything inside tmux and a network blip costs you nothing.
- Visibility. Splitting panes lets you watch a program, its debugger, and its logs simultaneously — invaluable for memory-corruption and fuzzing work.
- Collaboration & handoff. Two clients can attach to one session at once (pair debugging), and a detached session is a clean handoff to your future self.
Key takeaways
- tmux is a terminal multiplexer: it persists sessions independently of any connection (detach/reattach) and splits one terminal into windows and panes.
- The client-server model is why work survives a disconnect — the server holds your sessions; clients merely attach and detach.
- The hierarchy is session → window → pane; nearly everything is the prefix (
C-b, often rebound toC-a) followed by a key. - Core moves:
tmux new -s name/tmux attach -t name,C-b dto detach,C-b cnew window,C-b %/"to split,C-b zto zoom,C-b [for copy mode. - Configure it in
~/.tmux.conf; extend with tpm, resurrect/continuum (persistence across reboots), and tmuxinator (scripted layouts).
References
- tmux manual (
man tmux) and wiki. https://github.com/tmux/tmux/wiki - tmux Plugin Manager (tpm). https://github.com/tmux-plugins/tpm
- tmux-resurrect — persist sessions across reboots. https://github.com/tmux-plugins/tmux-resurrect
- tmuxinator — scripted session layouts. https://github.com/tmuxinator/tmuxinator
- tmux Config: Understanding the Options. https://thevaluable.dev/tmux-config-mouseless/
- tmux cheat sheet. https://tmuxcheatsheet.com/
Related course pages: SSH: Secure Shell · Process Management · Software Configuration · zsh: The Z Shell · Memory Corruption · Shell and Other Basics
🛠️ Maintenance note: tmux keybindings and config syntax are stable, but the config format changed at tmux 3.x in a few places (
set -goption names,bind -n), so older~/.tmux.confsnippets online may not load cleanly — verify against the tmux version on the course VM (tmux -V).