tmux: Persistent Terminal Sessions for Developers
Keep processes running after you disconnect, split your terminal into panes, and switch between projects without opening a new window.
Two things make tmux worth learning. Sessions survive after you close your terminal or lose an SSH connection — your processes keep running and you reconnect to find everything exactly where you left it. And you can split a single terminal into multiple panes and windows without juggling tabs.
Install
# Debian / Ubuntu
sudo apt install tmux
# RHEL / Fedora / Rocky
sudo dnf install tmux
# macOS
brew install tmux
Core concepts
tmux has three levels:
- Session — a collection of windows. One session per project is the natural fit.
- Window — a full-screen view inside a session. Think of it like a browser tab.
- Pane — a split region within a window. One window can hold several panes.
The prefix key is how you send commands to tmux without the keystrokes going to the program running inside it. The default is Ctrl+B. Press it, release, then press the command key.
Start and attach to sessions
Create a new named session:
tmux new -s myproject
Detach (session keeps running in the background):
Ctrl+B d
List sessions:
tmux ls
Reattach by name:
tmux attach -t myproject
Short form: tmux a -t myproject. With only one session, tmux a is enough.
Kill a session:
tmux kill-session -t myproject
Windows
| Action | Keys |
|---|---|
| New window | Ctrl+B c |
| Next window | Ctrl+B n |
| Previous window | Ctrl+B p |
| Go to window by number | Ctrl+B 0–9 |
| Rename current window | Ctrl+B , |
| Close current window | Ctrl+B & |
Windows appear in the status bar at the bottom. The active one has a * next to its name.
Panes
| Action | Keys |
|---|---|
| Split top/bottom | Ctrl+B " |
| Split left/right | Ctrl+B % |
| Move between panes | Ctrl+B arrow keys |
| Resize pane | Ctrl+B Ctrl+arrow keys |
| Zoom to full screen | Ctrl+B z (toggle) |
| Close current pane | Ctrl+B x |
Zoom is one of the most useful shortcuts — it temporarily expands a pane to fill the entire window without closing the others. Hit it again to return to the split view.
Scrollback and copy mode
Mouse scroll does not work inside tmux by default. To scroll:
Ctrl+B [
This enters copy mode. Arrow keys and Page Up/Page Down navigate. Press / to search, n for the next match, q to exit.
Auto-start a session on login
tmux sessions do not survive a reboot. For development machines where you always want a session waiting:
# add to ~/.bashrc or ~/.zshrc
if [ -z "$TMUX" ]; then
tmux attach -t main 2>/dev/null || tmux new -s main
fi
The [ -z "$TMUX" ] guard prevents tmux from launching inside an existing tmux session, which would nest them.
~/.tmux.conf
A minimal config that most people find immediately useful:
# Start window and pane numbering at 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1
# Enable mouse: click to focus panes, drag to resize
set -g mouse on
# Increase scrollback
set -g history-limit 10000
# Status bar: show session name on the left, time on the right
set -g status-left "[#S] "
set -g status-right "%H:%M"
Reload the config without restarting:
Ctrl+B :source-file ~/.tmux.conf
Mouse support is the single option worth enabling immediately if you are used to a GUI terminal. It makes pane navigation and resizing click-based while you build up the keyboard shortcuts.
SysEmperor