Overview
tmux (terminal multiplexer) lets you run multiple terminal sessions inside one window, split the screen into panes, and keep long-running processes alive after you disconnect. It is essential for anyone working on remote servers.
Why Use tmux?
| Feature | Benefit |
|---|---|
| Session persistence | Processes keep running after SSH disconnects |
| Split panes | Monitor logs and edit code side by side |
| Multiple windows | Organize work by project or task |
| Detach and reattach | Resume exactly where you left off |
Install tmux
# macOS
brew install tmux
# Ubuntu / Debian
sudo apt install tmux
# CentOS / RHEL
sudo yum install tmux
Starting and Detaching
tmux start a new session
tmux new -s work start a named session
tmux ls list sessions
tmux attach -t work reattach to a session
tmux kill-session -t work kill a session
Inside tmux, the default prefix key is Ctrl+b. Every shortcut below starts with the prefix.
Session Management
| Shortcut | Action |
|---|---|
Ctrl+b d | Detach from session |
Ctrl+b s | List and switch sessions |
Ctrl+b $ | Rename current session |
Ctrl+b ? | Show all key bindings |
Windows
| Shortcut | Action |
|---|---|
Ctrl+b c | Create a new window |
Ctrl+b n / p | Next / previous window |
Ctrl+b 0-9 | Switch to window by number |
Ctrl+b , | Rename current window |
Ctrl+b & | Close current window |
Panes
| Shortcut | Action |
|---|---|
Ctrl+b % | Split vertically |
Ctrl+b " | Split horizontally |
Ctrl+b arrow key | Move between panes |
Ctrl+b o | Cycle through panes |
Ctrl+b z | Toggle pane zoom |
Ctrl+b x | Close current pane |
Ctrl+b space | Cycle pane layouts |
Copy Mode
Ctrl+b [ enter copy mode
Space start selection
Enter copy selection
Ctrl+b ] paste
In copy mode, use arrow keys or hjkl to navigate.
Sample .tmux.conf
# Use Ctrl+a as prefix (screen-style)
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Enable mouse support
set -g mouse on
# Start window numbering at 1
set -g base-index 1
setw -g pane-base-index 1
# Faster key repeat
set -sg escape-time 10
# Reload config
bind r source-file ~/.tmux.conf \; display "Config reloaded"
Reload the config inside tmux with Ctrl+b :source-file ~/.tmux.conf.
Typical Server Workflow
ssh user@server
tmux new -s deploy
# run a long build or deployment
# press Ctrl+b d to detach
# reconnect later
ssh user@server
tmux attach -t deploy 