Getting Started with tmux - Terminal Multiplexing Basics
What You'll Learn
- Keep work running on a remote server even when SSH disconnects using
tmux - Understand the three-layer model: sessions, windows, panes
- Get comfortable with prefix-key combos starting with
Ctrl+b - Detach (step away) and attach (return) freely without losing state
- Split a single terminal screen to run multiple tasks in parallel
Target Audience: Anyone who does SSH work on remote servers and has lost progress to a flaky connection, or anyone tired of opening only one terminal at a time.
Introduction: The Day Lina Lost Her Logs
tmux.The Practical Pattern
- Before long jobs, enter
tmuxfirst (this alone kills 90% of SSH accidents) - To step away:
Ctrl+b→d(detach) - To return:
tmux attach— your screen is back - More screens? Use windows (
Ctrl+b c) - Split current screen? Use panes (
Ctrl+b %/Ctrl+b ")
1. Install tmux
Check the Version
$ tmux -V
tmux 3.4
If you see "command not found," you need to install it.
Ubuntu / Debian
$ sudo apt update $ sudo apt install tmux
CentOS / RHEL / Rocky Linux
$ sudo dnf install tmux
No root access? On shared servers where sudo isn't allowed, ask the admin. Don't drop random binaries into /usr/local/bin/ without checking the policy first.
2. Your First tmux Session
tmux and hit Enter. Nothing else.Ctrl+b → d always gets you out safely. Remember just that escape hatch and you can't get lost.Open a Session
$ tmux
You'll see a green status bar appear at the bottom. That's your visual proof that you're inside tmux.
[0] 0:bash* "hostname" 14:00 23-May-26
Try Some Commands
Inside, it's just a regular shell. Try running anything.
$ echo "running inside tmux" $ pwd
3. Detach and Attach - tmux's Killer Feature
Detach: Ctrl+b → d
While inside tmux, press these keys in sequence:
Ctrl+b d
The green status bar disappears and you're back to your regular terminal.
[detached (from session 0)] $
Important mental model: You didn't close it, you stepped away. On the server side, the tmux session is still alive and well.
List Sessions
$ tmux ls
0: 1 windows (created Fri May 23 14:00:00 2026)
Session 0 is still there. Alive and waiting.
Attach: Come Back
$ tmux attach
Your screen comes back exactly as you left it. Command history, open files, running processes — all preserved.
tmux. Wi-Fi drops? Close your laptop? Doesn't matter — the tmux session keeps living. SSH back in later, tmux attach, and resume like nothing happened.Common confusion: Typing exit in the shell destroys the session. To step away you must use Ctrl+b → d (detach). exit closes the session, and tmux attach won't bring it back.
4. What Is a Prefix Key?
Ctrl+b.Ctrl+b, d means "detach," c means "new window," and so on. The prefix is how tmux avoids stealing every keystroke from your shell.The Prefix Pattern
Ctrl+b → some key
Ctrl+b is not held down. Press and release Ctrl+b, then press the next key.
The five prefix commands worth memorizing first
| Keys | Action |
|---|---|
Ctrl+b d |
Detach |
Ctrl+b c |
New window |
Ctrl+b n |
Next window |
Ctrl+b % |
Split pane vertically |
Ctrl+b " |
Split pane horizontally |
5. Windows: Switching Between Screens
Create a New Window
Ctrl+b c
c is for create. A fresh window opens and you switch to it.
The status bar now shows:
[0] 0:bash- 1:bash*
Two windows: 0 and 1. * marks where you are; - marks the last one you visited.
Switch Between Windows
Ctrl+b n # Next window Ctrl+b p # Previous window Ctrl+b 0 # Jump to window 0 Ctrl+b 1 # Jump to window 1
Close a Window
Type exit in that window's shell. Or use Ctrl+b & (asks for confirmation).
6. Panes: Splitting One Screen
Split Vertically (Left and Right)
Ctrl+b %
The screen splits with a vertical line — two panes, left and right.
Split Horizontally (Top and Bottom)
Ctrl+b "
The screen splits with a horizontal line — two panes, top and bottom.
Memory trick:
%looks like a vertical bar → vertical split (left/right)"looks like a horizontal mark → horizontal split (top/bottom)
Many people find these backward at first. The key shape is the easiest mnemonic.
Move Between Panes
Ctrl+b ← # Move to the left pane Ctrl+b → # Move to the right pane Ctrl+b ↑ # Move to the upper pane Ctrl+b ↓ # Move to the lower pane Ctrl+b o # Cycle through panes
Close a Pane
Type exit in that pane, or press Ctrl+b x (asks for confirmation).
7. Common Beginner Pitfalls
Pitfall 1: Holding Ctrl+b Down
Symptom: The key after the prefix does nothing, or behaves oddly.
Cause: You're still holding Ctrl+b when pressing the next key.
Fix: Press Ctrl+b, release it, then press the next key.
Pitfall 2: Running tmux Inside tmux
Symptom: The status bar doubles up; prefix keys feel "off" (intercepted by the outer tmux).
Cause: You accidentally typed tmux in a shell that was already inside tmux.
Fix: exit the inner session, or detach completely and run tmux ls to inspect what's there.
Pitfall 3: Killed the Session with exit
Symptom: tmux attach says "no sessions."
Cause: You typed exit thinking you were "stepping away," but exit destroys the session.
Fix: There's no undo. Next time, use Ctrl+b → d to detach instead.
8. The Production Template: Protect SSH Work with tmux
Copy-paste safe pattern
# 1. SSH into the server ssh user@server # 2. Immediately enter tmux (attach if a session exists, otherwise create) tmux attach || tmux # 3. Do your work normally (long log tailing, builds, backups, etc.) tail -f /var/log/syslog # ... # 4. To step away: Ctrl+b → d (detach) # 5. Now SSH can die safely - the session lives on the server # 6. To return: SSH back in, then tmux attach
This one pattern eliminates the majority of SSH-related work loss.
Mini Challenges - Get Hands-On
Challenge 1: Open a Session, Detach, Reattach
$ tmux # → you're inside tmux now $ echo "test" # Press Ctrl+b → d to detach $ tmux ls # → confirm the session is still alive $ tmux attach # → your screen returns
Challenge 2: Create Two Windows and Switch Between Them
$ tmux # Ctrl+b c to create window 1 # Ctrl+b 0 to jump to window 0 # Ctrl+b 1 to jump to window 1 # Ctrl+b n to cycle to the next
Challenge 3: Split One Window into Panes
$ tmux # Ctrl+b % to split vertically # Ctrl+b " to split horizontally # Ctrl+b arrow-keys to move between panes # Run different commands in each pane (e.g., top, df -h, tail -f /var/log/syslog)
~/.tmux.conf.Today's Three-Line Summary
tmuxto enter,Ctrl+b → dto leave,tmux attachto return — this trio eliminates SSH disconnect disasters- The prefix key (
Ctrl+b) followed by a command key is the rhythmic core of tmux operation - Keeping the session > window > pane hierarchy in mind unlocks dramatically more efficient parallel work