tmux is a terminal multiplexer. It lets you run multiple terminal sessions inside a single window, detach from them, and reattach later — even from a different machine. The win that hooks most people: if your SSH connection drops mid-lab, your work doesn't die. The shell keeps running, the file copy keeps going, the long-running test keeps progressing. When you reconnect, you reattach exactly where you left off.
For this course there is one bonus: tmux can capture the entire scrollback of any pane to a text file. That's a separate path to "save my work for the deliverable" alongside script and asciinema.
Install
The three concepts
tmux organizes terminals into a three-level hierarchy:
- Session — the top-level thing. Has a name. Lives on the server independent of any client. You attach to it and detach from it.
- Window — like a browser tab. One window fills the visible area; you switch between windows with a keystroke.
- Pane — a split of a window. Multiple shells visible side-by-side in the same window.
The prefix key
Every tmux command starts with a prefix key, then a second key. The default prefix is Ctrl+b. Throughout the rest of this page, you'll see notation like Ctrl+b d — that means: press Ctrl+b, release it, then press d.
Ctrl+a (matching GNU screen). To do that, add set -g prefix C-a + unbind C-b + bind C-a send-prefix to your ~/.tmux.conf. For this page we'll assume the default Ctrl+b.The first five minutes
Start a session
Detach — the killer feature
tmux exits and drops you back at your normal shell. But the session keeps running. Close the terminal window, disconnect your SSH, walk away — the session is still there.
Reattach
Common workflow
SSH into a lab box, start tmux, run a long task (a network scan, a backup, a fuzzing run), detach, close your laptop. Re-open the laptop the next morning, SSH back in, reattach the tmux session, the task has finished, the output is right there. Your work is not tied to your SSH connection's lifetime.
Cheat sheet — the keys you'll use daily
| Keystroke | What it does |
|---|---|
| Sessions | |
| Ctrl+b d | Detach (session keeps running) |
| Ctrl+b $ | Rename the current session |
| Ctrl+b s | Pick a session from the list (when you have several) |
| Windows | |
| Ctrl+b c | Create a new window |
| Ctrl+b n | Next window |
| Ctrl+b p | Previous window |
| Ctrl+b 0..9 | Jump to window number 0..9 |
| Ctrl+b , | Rename the current window |
| Ctrl+b w | Interactive window picker |
| Panes (splits) | |
| Ctrl+b % | Split vertically (panes side-by-side) |
| Ctrl+b " | Split horizontally (panes stacked) |
| Ctrl+b arrow | Move between panes |
| Ctrl+b z | Toggle "zoom" on current pane (full-screen / restore) |
| Ctrl+b x | Kill the current pane (asks first) |
| Ctrl+b { / } | Swap pane with the previous / next pane |
| Scrolling & copying | |
| Ctrl+b [ | Enter copy mode (now you can scroll back with arrows / Page Up) |
| q (in copy mode) | Exit copy mode back to normal |
| Ctrl+b ] | Paste the most recent copy buffer |
| Help | |
| Ctrl+b ? | Show every key binding (with /search support) |
Saving a pane to a file — for lab submission
tmux can dump the contents of a pane (including scrollback) to a text file. This is the alternative to script when you've already been working in tmux:
-S - means "from the start of the scrollback." Without it, you only get the currently visible portion. -p prints to stdout (useful for piping to a file from outside tmux). For end-of-class deliverables this gives you a clean text file with everything that scrolled past during the session.
A ~/.tmux.conf worth having
Drop this in ~/.tmux.conf for a more humane experience:
Reload without restarting:
tmux gives you three things: persistent sessions that survive SSH drops, splits so you can have an editor and a shell side by side, and pane capture so your scrollback isn't ephemeral. The learning curve is real but small — ten keystrokes will get you 90% of the value.
The day you start a long-running task on a remote box, detach with Ctrl+b d, close your laptop, walk away, come back, reattach, and find the task done — that's when tmux becomes permanent muscle memory.
References
Formatted in APA 7. Alphabetized by first author's last name.
- Hogan, B. P. (2016). tmux 2: Productive mouse-free development. Pragmatic Bookshelf.
- Marriott, N. (n.d.). tmux: A terminal multiplexer. https://github.com/tmux/tmux/wiki
- tmux contributors. (n.d.). tmux(1): Linux manual page. https://man7.org/linux/man-pages/man1/tmux.1.html