Keep your terminal sessions alive.
What is tmux?
tmux lets you create a terminal session that keeps running even when you disconnect from SSH, close your terminal, or lose your connection.
Think of it as a persistent workspace inside your terminal.
1. Start tmux
tmux
You are now inside a tmux session.
Anything you run here continues running even if you disconnect.
2. The Magic Key: Ctrl + B
Tmux commands usually start with:
Ctrl + B
Then press another key.
Important: Don't hold both keys for the second command.
Example:
Ctrl + B, D
means:
- Press
Ctrl + B - Release them
- Press
D
3. Detach from a Session
Want to leave tmux without stopping what is running?
Ctrl + B, D
You'll return to your normal terminal.
Your programs are still running.
4. Get Back Into tmux
tmux attach
or:
tmux a
You'll return to where you left off.
5. See Your Sessions
tmux ls
Example:
0: 1 windows
This tells you that a tmux session exists.
6. Give Your Session a Name
Instead of having sessions called 0, 1, etc.:
tmux new -s myapp
Then reconnect later with:
tmux attach -t myapp
This is especially useful on servers.
7. Create Another Window
Inside tmux:
Ctrl + B, C
C = Create
You can now have multiple terminal windows inside the same tmux session.
8. Move Between Windows
Ctrl + B, N
N = Next
Or:
Ctrl + B, P
P = Previous
You can also use:
Ctrl + B, 0
Ctrl + B, 1
Ctrl + B, 2
to jump directly to a window.
9. Split the Terminal
Split horizontally
Ctrl + B, %
Split vertically
Ctrl + B, "
Now you can have multiple terminals visible at once.
10. Move Between Panes
Ctrl + B, Arrow Key
For example:
Ctrl + B, ↑
moves to the pane above.
11. Close a Pane
Just type:
exit
Or press:
Ctrl + D
The pane closes when the shell running inside it exits.
The 10 Commands to Remember
| What you want | Command |
|---|---|
| Start tmux | tmux |
| Start named session | tmux new -s name |
| Detach | Ctrl+B, D |
| Reconnect | tmux a |
| List sessions | tmux ls |
| New window | Ctrl+B, C |
| Next window | Ctrl+B, N |
| Previous window | Ctrl+B, P |
| Split horizontally | Ctrl+B, % |
| Split vertically | Ctrl+B, " |
A Typical Server Workflow
SSH into your server:
ssh user@server
Start a named tmux session:
tmux new -s deployment
Run your long-running command:
./deploy.sh
Detach:
Ctrl + B, D
You can now safely disconnect from SSH.
Later:
ssh user@server
tmux attach -t deployment
You're back exactly where you left off.
The One Thing to Remember
If you're running something important over SSH, put it inside tmux.
That's probably enough tmux for a beginner. Learn the rest when you actually need it.
