Skip to main content

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.

Learning Focus

Use this lesson to understand tmux's mental model (server, sessions, windows, panes) so you can use it confidently in production server work.

Core Idea

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]
LayerWhat it isAnalogy
ServerBackground tmux daemonApp server
SessionNamed workspace groupBrowser profile
WindowA tab inside a sessionBrowser tab
PaneA split inside a windowSplit editor view

Why Operators Use Tmux

NeedTmux capabilityPractical effect
SSH safetySessions survive disconnectsLong jobs never get killed
Multi-taskingWindows + panesEditor, logs, shell — all visible
Remote collaborationShared sessionsTwo people in same session
AutomationScript-driven layoutsPre-built dev/ops dashboards
MonitoringTiled pane layoutHtop, logs, app status — side by side

Tmux vs Screen vs SSH Alone

FeatureTmuxScreenSSH alone
Persistent sessions
Multiple windows
Pane splittingLimited
Scriptable layouts
Status bar✅ customizableBasic
Plugin ecosystem✅ (TPM)
Active developmentMinimal
tip

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
warning

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)

MistakeWhat happensFix
Closing terminal instead of detachingSession is killedAlways use Ctrl+b d to detach
Forgetting to name sessionsHard to find the right oneAlways use -s name
Nesting tmux inside tmuxPrefix confusionBe aware of nesting; use distinct configs
Using exit in all panesKills the window/sessionJust 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

What's Next