tmux: terminal multiplexing made simple
tmux lets you create multiple terminal sessions inside one window, split the screen into panes, and most importantly, keep sessions alive when you disconnect from SSH. If you’ve ever lost a long-running process because your SSH connection dropped, tmux is the answer.
Why tmux
- Session persistence — disconnect from SSH, reconnect later, everything is still running
- Multiple windows — like browser tabs for your terminal
- Split panes — see multiple things at once in one terminal
- Shared sessions — two people can attach to the same session (pair programming, debugging)
Starting tmux
tmux
That creates a session and attaches to it. You’re now inside tmux.
Detach (leave tmux running, return to normal terminal):
Ctrl+b d
Reattach:
tmux attach
# or
tmux a
List sessions:
tmux ls
Named sessions:
tmux new -s work
tmux attach -t work
Windows (tabs)
Create a new window: Ctrl+b c
Switch to next window: Ctrl+b n
Switch to previous window: Ctrl+b p
Switch by number: Ctrl+b 0 (or 1, 2, etc.)
List windows: Ctrl+b w
Rename window: Ctrl+b ,
Close window: Ctrl+b &
Panes (splits)
Split horizontally: Ctrl+b %
Split vertically: Ctrl+b "
Switch to next pane: Ctrl+b o
Switch by direction: Ctrl+b ←↑↓→
Close pane: Ctrl+b x
Zoom pane (fullscreen toggle): Ctrl+b z
Resize pane: Ctrl+b Ctrl+←↑↓→
Copy mode
Enter copy mode: Ctrl+b [
Navigate with arrow keys or vi keys (j/k)
Start selection: Space (in vi mode)
Copy selection: Enter
Paste: Ctrl+b ]
Exit copy mode: q
Configuration
tmux config goes in ~/.tmux.conf. Some useful settings:
# Enable mouse support
set -g mouse on
# Start window numbering from 1
set -g base-index 1
setw -g pane-base-index 1
# Increase history limit
set -g history-limit 50000
# Vi-style copy mode
setw -g mode-keys vi
# Reload config
bind r source-file ~/.tmux.conf \; display "Config reloaded"
Practical workflows
Long-running tasks:
tmux new -s deploy
# start your deployment script
# detach with Ctrl+b d
# reconnect later with tmux attach -t deploy
Multiple projects:
tmux new -s frontend
tmux new -s backend
tmux new -s ops
Switch between them with tmux switch -t name.
Side-by-side logs:
tmux
# split vertically: Ctrl+b %
# in left pane: tail -f /var/log/nginx/access.log
# click to right pane: Ctrl+b o
# in right pane: tail -f /var/log/nginx/error.log
tmux vs screen
GNU screen does similar things. tmux has:
- Better split pane support
- Scriptable (you can automate layouts)
- Cleaner configuration
- Active development
screen is older and simpler. If you’re choosing today, tmux is the better option.
Common tmux commands
tmux # new session
tmux new -s name # named session
tmux ls # list sessions
tmux attach -t name # attach to session
tmux kill-session -t name # kill a session
tmux kill-server # kill tmux entirely
Common mistakes
Not using tmux for remote work. Every SSH session that runs a long task should be inside tmux. Connection drops are inevitable.
Nested tmux. If you SSH from a tmux session into another server running tmux, the keybindings conflict. Use different prefix keys or use tmux only on the remote server.
Not knowing how to exit. exit or Ctrl+d closes the current pane/window. When the last pane closes, the session ends.
Remarks
tmux is one of those tools that, once you learn it, you wonder how you lived without it. The basics — new session, split pane, detach/attach — take 10 minutes to learn. The investment pays off every time your SSH connection drops and your work is still there.
Related Posts
Vim survival guide for Linux admins
The minimum vim knowledge you need to survive on a Linux server. Editing config files without wanting to throw your keyboard.
Linux memory management: free, vmstat, and /proc
Understanding how Linux uses memory. Reading free correctly, using vmstat, and what /proc/meminfo actually tells you.
Managing SSL certificates with Let's Encrypt
Getting free SSL certificates with Let's Encrypt and certbot. Installation, renewal, and troubleshooting.