Terminal Multiplexing with tmux๐
Part of a pathway: Debugging With Nothing But a Terminal
Consult the map
-
Debugging With Nothing But a Terminal โ step 13 of 20
โ Vim Survival Mode ยท you are here ยท FZF Mastery โ
Your SSH connection just dropped during a long-running database migration. Without a multiplexer, your session is gone, and the process might be in an unknown state. With tmux, you just reconnect and pick up exactly where you left off. This is why tmux is a non-negotiable tool for SREs.
tmux (Terminal Multiplexer) lets you manage multiple terminal sessions from a single window. More importantly, it keeps those sessions alive on the server even if your connection breaks.
Installation๐
| Install tmux on macOS | |
|---|---|
tmux is a Unix tool with no native Windows build. Use it inside WSL:
| Install tmux inside WSL | |
|---|---|
Quick Start: The 3-Command Survival Guide๐
If you're new to tmux, these three commands provide 90% of the value:
- Start a session:
tmux new -s my-work - Detach (Leave it running): Press
Ctrl+bthend - Attach (Get back to it):
tmux attach -t my-work
How Tmux Works๐
tmux sits between your terminal emulator and the shell. It manages a Server that hosts multiple Sessions. Each session can have multiple Windows, and each window can be split into multiple Panes.
graph TD
Server[Tmux Server] --> SessionA[Session: Incident-123]
Server --> SessionB[Session: Maintenance]
SessionA --> Win1[Window 1: Logs]
SessionA --> Win2[Window 2: Editor]
Win1 --> Pane1[Pane: tail -f access.log]
Win1 --> Pane2[Pane: htop]
style Server fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style SessionA fill:#d69e2e,stroke:#cbd5e0,stroke-width:2px,color:#000
style SessionB fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Win1 fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Win2 fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Pane1 fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Pane2 fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
The Prefix Key๐
Most tmux commands are triggered by a Prefix. By default, this is Ctrl+b. You press the prefix, release it, and then press the command key.
-
Window Management
Why it matters: Keep different tasks (logging, editing, monitoring) in separate "tabs" within one SSH session.
Prefix+c: Create a new windowPrefix+n/p: Next/Previous windowPrefix+0-9: Jump to specific window
-
:material-columns: Pane Management
Why it matters: Watch logs and run commands side-by-side in the same view.
Prefix+": Split horizontallyPrefix+%: Split verticallyPrefix+Arrow Keys: Move between panesPrefix+z: Zoom (maximize) the current pane
-
Session Management
Why it matters: Persist your work across reboots or connection drops.
tmux ls: List running sessionstmux attach: Reconnect to the last sessionPrefix+d: Detach (disconnect without killing)
Why Tmux Matters for Platform Work๐
For an SRE, tmux is about resilience and multitasking.
Common Scenarios๐
When performing risky operations (like upgrading a kernel or migrating a database), always run them inside a tmux session. If your VPN drops or your Wi-Fi flutters, the operation continues safely on the server โ reconnect and you're looking at the same terminal, mid-command.
Split your screen into four quadrants โ logs, resource usage, cluster state, and a free shell for troubleshooting:
- Top Left:
tail -fthe error logs - Top Right:
htopfor system resources - Bottom Left:
kubectl get pods -w - Bottom Right: A shell for active troubleshooting
That's the first two cuts; see Multiple AI CLIs, One tmux Session for the pane-splitting mechanics that take you the rest of the way to four. A common variant once you're past initial triage: swap one quadrant for an AI CLI to sanity-check a hypothesis while the other three keep watching the system.
Two people can attach to the same tmux session on a server. This is a "poor man's screen sharing" that is incredibly effective for remote pair-debugging without any special software.
| Attach to a Shared Session | |
|---|---|
Both people run this against the same session name โ whatever either of you types, the other sees in real time.
Practice Problems๐
Practice Problem 1: The Panic Button
You're inside tmux and everything is frozen. How do you kill the entire session and get back to your normal shell?
Answer
Type exit in every pane, or use the command Prefix + :kill-session followed by Enter. If you're completely stuck, you can run tmux kill-server from outside tmux in another terminal.
Practice Problem 2: Finding Your Way
You have 10 windows open in a session and forgot which one has your editor. What's the fastest way to see a list of all windows and pick one?
Answer
Press Prefix + w. This opens an interactive, searchable list of all windows and panes. You can use the arrow keys to navigate and Enter to switch to the selected one.
Key Takeaways๐
| Action | Command / Shortcut |
|---|---|
| Prefix | Ctrl+b (Default) |
| New Session | tmux new -s <name> |
| Detach | Prefix + d |
| Attach | tmux attach -t <name> |
| Split Vertically | Prefix + % |
| Split Horizontally | Prefix + " |
| Zoom Pane | Prefix + z |
What's Next๐
If you're following the Debugging With Nothing But a Terminal pathway, the next step is FZF Mastery โ panes and windows solve where things run, fzf solves picking what to run them on, without memorizing exact pod, branch, or file names.
Further Reading๐
Official Documentation๐
- Tmux Wiki - The official source for documentation and FAQs.
man tmux- The comprehensive manual page.
Related Tools & Alternatives๐
- tmate - Instant terminal sharing based on tmux.
- tmux-resurrect - Plugin to persist sessions across system reboots.
Deep Dives๐
- The Tao of Tmux - A philosophical and technical deep dive into tmux workflows.