Getting Started with tmux - Terminal Multiplexing Basics
What you'll be able to do
- Set up a workspace with tmux that survives an SSH disconnect
- Explain the three layers: session, window, and pane
- Pause work with detach and resume it later with attach
Prerequisites (read these first)
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 terminalAn interactive program that reads the commands you type and runs them. 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 prevents.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 ")
Learn the escape hatch first
tmux changes how your screen looks. That is why beginners often feel trapped. When in doubt, these three moves get you out.
| Stuck state | How to get out |
|---|---|
| Lost inside tmux | Press Ctrl+b, release it, then press d (detach) |
| Want your screen back after detach | tmux attach |
| Not sure whether you are inside | Run echo $TMUX — any output means you are inside tmux. |
Ctrl+b → d always works. Those two keystrokes bring you back to your normal terminal.
And if you do destroy a session, only the screen is gone. Saved files stay right where they are, so experiment calmly.
1. Install tmux
Conclusion: tmux is not always preinstalled; check with tmux -V and install via apt or dnf.
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
Can't install it? On shared servers, sudo (the mechanism for running a command as the administrator) is often unavailable. In that case don't install it yourself — ask the server administrator.
2. Your First tmux Session
Conclusion: Just type tmux to start a session; the green status bar confirms you are inside.
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.What a session is
A session is one workspace that tmux keeps for you. Think of reserving one table at a cafe. You can leave your things (running commands) on the table. Step away and your things are still there when you return.
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. A shell is the program that takes the commands you type and runs them — bash and zsh are the common ones. Try running anything.
$ echo "running inside tmux" $ pwd
3. Detach and Attach - tmux's Killer Feature
Conclusion: Detach with Ctrl+b d, return with tmux attach; the session lives on the server.
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. After that you just work normally.tmux attach, and resume like nothing happened.Lina's Mistake: Destroying a Session with exit
exit to step away, and now tmux attach says "no sessions". Where did my work go?exit is the command for closing a session. It is not the same as detaching.Ctrl+b → d steps away from the table. exit folds the table up. From today, save exit for when you are truly done.Ctrl+b → d into my fingers!Common confusion: Typing exit in the shell destroys the session. A destroyed session cannot be brought back by tmux attach. The only way to step away is Ctrl+b → d (detach).
4. What Is a Prefix Key?
Conclusion: The prefix key (Ctrl+b) signals tmux: release it, then press the command 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
Conclusion: Windows are like browser tabs: create with Ctrl+b c, switch with n/p/numbers.
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
Conclusion: Panes split one window: Ctrl+b % goes left/right, the quoteWrapping a string in quote marks (' or ") so it is treated as one single value, e.g. one with spaces in it. key goes top/bottom.
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
Conclusion: The big three pitfalls: holding the prefix, nesting tmux, and exit killing it.
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: You typed tmux, no new screen opened, and only this message appeared.
sessions should be nested with care, unset $TMUX to force
Cause: You are already inside tmux. By default, tmux refuses to nest itself.
Fix: Nothing is broken. Keep using the session you are already in. To confirm where you are, run echo $TMUX — any output means you are inside tmux.
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
Conclusion: SSH in, run tmux attach or tmux, detach with Ctrl+b d, return with tmux attach.
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
Conclusion: Practice detach/attach, window switching, and pane splitting to build memory.
Challenge 1: Open a Session, Detach, Reattach
Task: Open one tmux session. Step away from it, then come back.
Show Hint 1 (Direction)
Use the move that "steps away," not the one that closes. After stepping away, check whether the session is still listed.
Show Hint 2 (Command name)
Open with tmux. Step away with Ctrl+b → d. List with tmux ls. Return with tmux attach.
Show Answer
$ 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
Task: Create a second window inside tmux. Move back and forth between the two.
Show Hint 1 (Direction)
A window is the tmux version of a browser tab. First do the "create" move, then try selecting a window by its number.
Show Hint 2 (Command name)
Create with Ctrl+b → c. Select by number with Ctrl+b → 0 or Ctrl+b → 1. Cycle with Ctrl+b → n.
Show Answer
$ 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
Task: Split the screen left and right. Then split it top and bottom, and run a different command in each pane.
Show Hint 1 (Direction)
Two symbols do the splitting. Match the shape of each key to the direction of the split. Movement uses the arrow keys.
Show Hint 2 (Command name)
Split left/right with Ctrl+b → %. Split top/bottom with Ctrl+b → ". Move with Ctrl+b → arrow key.
Show Answer
$ 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