What is Tmux
Tmux is a terminal multiplexer. It lets you open multiple terminal sessions inside a single window, organize them into windows and panes, and most importantly — detach and reattach without losing your work.
Use this lesson to understand tmux's mental model (server, sessions, windows, panes) so you can use it confidently in production server work.
Tmux runs as a background server. Your terminal is just a client connecting to it. When you disconnect, the server keeps running — your sessions are safe.
The Problem Tmux Solves
Without tmux:
sequenceDiagram
participant DEV as Developer
participant SSH as SSH Session
participant PROC as Running Process
DEV->>SSH: Connect & start long job
SSH->>PROC: Process running...
SSH-->>DEV: Connection drops!
PROC-->>PROC: ❌ Process killed — work lost
With tmux:
sequenceDiagram
participant DEV as Developer
participant SSH as SSH Session
participant TMUX as Tmux Server
DEV->>SSH: Connect
SSH->>TMUX: Start session, run long job
SSH-->>DEV: Connection drops!
TMUX-->>TMUX: ✅ Server keeps running
DEV->>SSH: Reconnect
SSH->>TMUX: Reattach — job still running
How Tmux Is Structured
flowchart TD
SERVER[Tmux Server Process]
SERVER --> S1[Session: work]
SERVER --> S2[Session: monitoring]
S1 --> W1[Window 1: code]
S1 --> W2[Window 2: git]
W1 --> P1[Pane: vim]
W1 --> P2[Pane: terminal]
S2 --> W3[Window 1: htop]
| Layer | What it is | Analogy |
|---|---|---|
| Server | Background tmux daemon | App server |
| Session | Named workspace group | Browser profile |
| Window | A tab inside a session | Browser tab |
| Pane | A split inside a window | Split editor view |
Why Operators Use Tmux
| Need | Tmux capability | Practical effect |
|---|---|---|
| SSH safety | Sessions survive disconnects | Long jobs never get killed |
| Multi-tasking | Windows + panes | Editor, logs, shell — all visible |
| Remote collaboration | Shared sessions | Two people in same session |
| Automation | Script-driven layouts | Pre-built dev/ops dashboards |
| Monitoring | Tiled pane layout | Htop, logs, app status — side by side |
Tmux vs Screen vs SSH Alone
| Feature | Tmux | Screen | SSH alone |
|---|---|---|---|
| Persistent sessions | ✅ | ✅ | ❌ |
| Multiple windows | ✅ | ✅ | ❌ |
| Pane splitting | ✅ | Limited | ❌ |
| Scriptable layouts | ✅ | ❌ | ❌ |
| Status bar | ✅ customizable | Basic | ❌ |
| Plugin ecosystem | ✅ (TPM) | ❌ | ❌ |
| Active development | ✅ | Minimal | — |
In 2024+, tmux is the standard choice. Use screen only when tmux is unavailable.
The Prefix Key
Every tmux command starts with a prefix key combination (default: Ctrl+b), followed by another key.
Ctrl+b, then d → Detach from session
Ctrl+b, then c → Create new window
Ctrl+b, then % → Split pane vertically
Ctrl+b, then " → Split pane horizontally
You must press and release Ctrl+b before pressing the second key. Do not hold all keys at once.
Basic Commands Overview
# start a named session
tmux new-session -s mywork
# list all sessions
tmux ls
# attach to a session
tmux attach -t mywork
# kill a session
tmux kill-session -t mywork
Common Mistakes (Beginners)
| Mistake | What happens | Fix |
|---|---|---|
| Closing terminal instead of detaching | Session is killed | Always use Ctrl+b d to detach |
| Forgetting to name sessions | Hard to find the right one | Always use -s name |
| Nesting tmux inside tmux | Prefix confusion | Be aware of nesting; use distinct configs |
Using exit in all panes | Kills the window/session | Just close the pane, not the session |
Hands-On Practice
Try this on any Linux machine with tmux installed:
# start a session and run something
tmux new-session -s lab
top
# press Ctrl+b, then d to detach
# verify the session is still running
tmux ls
# reattach
tmux attach -t lab
# exit top, then kill the session
tmux kill-session -t lab