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?

FeatureBenefit
Session persistenceProcesses keep running after SSH disconnects
Split panesMonitor logs and edit code side by side
Multiple windowsOrganize work by project or task
Detach and reattachResume 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

ShortcutAction
Ctrl+b dDetach from session
Ctrl+b sList and switch sessions
Ctrl+b $Rename current session
Ctrl+b ?Show all key bindings

Windows

ShortcutAction
Ctrl+b cCreate a new window
Ctrl+b n / pNext / previous window
Ctrl+b 0-9Switch to window by number
Ctrl+b ,Rename current window
Ctrl+b &Close current window

Panes

ShortcutAction
Ctrl+b %Split vertically
Ctrl+b "Split horizontally
Ctrl+b arrow keyMove between panes
Ctrl+b oCycle through panes
Ctrl+b zToggle pane zoom
Ctrl+b xClose current pane
Ctrl+b spaceCycle 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