TL;DR — Quick Summary
Master tmux session management for remote servers. Learn persistent sessions, pane layouts, custom config, plugins, scripting, and practical DevOps workflows.
If you have ever lost hours of work because an SSH connection dropped mid-deployment, or found yourself juggling a dozen terminal windows to monitor a remote server, tmux is the tool that solves both problems permanently. Tmux (terminal multiplexer) runs a persistent server process on the remote host — your sessions, panes, and running commands survive disconnections, reboots of your local machine, and network failures alike. This guide covers everything you need: installation, the session-window-pane hierarchy, every essential keybinding, a production-ready ~/.tmux.conf, the tmux plugin ecosystem, scripting automated environments, and three practical DevOps workflows.
Prerequisites
Before starting, you need:
- A Linux or macOS system with terminal access (local or via SSH)
sudoprivileges for installation- Basic familiarity with the command line
- An SSH client if working with remote servers
Why tmux? The Core Use Cases
Three scenarios make tmux indispensable for remote server work:
Surviving SSH disconnects. When your ISP hiccups or your laptop lid closes, any process running in a plain SSH terminal dies. With tmux, the session continues on the server. Your long-running rsync, ansible-playbook, or npm run build keeps going. You reconnect and reattach.
Multi-pane workflows. A typical deployment might involve watching logs in one pane, running migration scripts in another, and having a shell ready for rollback commands in a third — all in a single SSH connection with a single window.
Pair programming. Two engineers can SSH into the same server and attach to the same tmux session. Both see and interact with the same terminal in real time. No screen-sharing software required.
Installation
Tmux is available in the default repositories of every major distribution.
Ubuntu/Debian:
sudo apt update && sudo apt install -y tmux
Fedora/RHEL/CentOS:
sudo dnf install -y tmux
Arch Linux:
sudo pacman -S tmux
macOS (Homebrew):
brew install tmux
Verify:
tmux -V
# tmux 3.4
Any version 3.0 or later supports all features in this guide.
Core Concepts: Sessions, Windows, and Panes
The tmux hierarchy has three levels. Understanding this before touching the keyboard prevents confusion:
Session — The outermost container. A named, independent workspace. You can have many sessions running simultaneously: work, deploy, monitor. Sessions persist even when you are not attached.
Window — Lives inside a session. Occupies the full screen, like a browser tab. Each session can have multiple windows. The status bar at the bottom shows all windows.
Pane — A subdivision of a window. You split a window horizontally or vertically to create multiple panes, each running its own shell or command.
tmux server (persistent on remote host)
|
+-- Session: "work"
| +-- Window 0: "editor"
| | +-- Pane 0: vim src/app.py
| | +-- Pane 1: python -m pytest
| +-- Window 1: "logs"
| +-- Pane 0: tail -f /var/log/app.log
|
+-- Session: "deploy"
+-- Window 0: "main"
+-- Pane 0: ansible-playbook deploy.yml
The prefix key signals tmux that the next keystroke is a command. Default prefix is Ctrl+b. You press Ctrl+b, release, then press the command key. Example: Ctrl+b c creates a new window.
Essential Keybindings
Here is the complete reference for day-to-day tmux usage (default Ctrl+b prefix):
| Action | Keybinding |
|---|---|
| Sessions | |
| Detach from session | Ctrl+b d |
| List and switch sessions | Ctrl+b s |
| Rename current session | Ctrl+b $ |
| Previous session | Ctrl+b ( |
| Next session | Ctrl+b ) |
| Windows | |
| Create new window | Ctrl+b c |
| Rename current window | Ctrl+b , |
| Next window | Ctrl+b n |
| Previous window | Ctrl+b p |
| Switch to window by number | Ctrl+b 0-9 |
| List and select windows | Ctrl+b w |
| Kill current window | Ctrl+b & |
| Panes | |
| Split vertically (left/right) | Ctrl+b % |
| Split horizontally (top/bottom) | Ctrl+b " |
| Navigate panes | Ctrl+b ←↑↓→ |
| Cycle through panes | Ctrl+b o |
| Show pane numbers | Ctrl+b q |
| Zoom pane (toggle full screen) | Ctrl+b z |
| Swap with previous pane | Ctrl+b { |
| Swap with next pane | Ctrl+b } |
| Break pane into new window | Ctrl+b ! |
| Kill current pane | Ctrl+b x |
| Cycle layouts | Ctrl+b Space |
| Copy Mode | |
| Enter copy mode | Ctrl+b [ |
| Paste buffer | Ctrl+b ] |
| Exit copy mode | q |
| Other | |
| Command prompt | Ctrl+b : |
| List all keybindings | Ctrl+b ? |
| Reload config (if bound) | Ctrl+b r |
The zoom keybinding (Ctrl+b z) deserves special mention. It temporarily expands one pane to fill the entire window without destroying your layout. Press again to restore. Invaluable when you need to read long stack traces or copy large blocks of output.
Session Management
Sessions are the foundation of persistent remote work.
Creating Sessions
# Start a new unnamed session
tmux
# Start a new named session (always prefer this)
tmux new -s work
# Start a session running a specific command
tmux new -s logs "tail -f /var/log/syslog"
# Start a session in a specific directory
tmux new -s api -c /var/www/api
Always name your sessions. When you have three or four running, names are the only way to distinguish them quickly.
Listing and Switching Sessions
# List all sessions from outside tmux
tmux ls
# Example output:
# deploy: 2 windows (created Sun Mar 22 09:15:22 2026)
# monitor: 1 windows (created Sun Mar 22 08:30:15 2026) (attached)
# work: 3 windows (created Sun Mar 22 07:45:00 2026)
From inside tmux, press Ctrl+b s to get an interactive tree of all sessions and windows. Use arrow keys to navigate, Enter to switch.
Attaching and Detaching
# Detach from current session (session keeps running)
# Press Ctrl+b then d
# Attach to the most recent session
tmux attach
# Attach to a specific session
tmux attach -t work
# Attach and detach any other clients (useful for screen size normalization)
tmux attach -t work -d
Renaming and Killing Sessions
# Rename a session from outside tmux
tmux rename-session -t old-name new-name
# Kill a specific session
tmux kill-session -t deploy
# Kill all sessions except the currently attached one
tmux kill-session -a
# Kill the tmux server (destroys everything)
tmux kill-server
Window Management
Windows are tabs within a session. Each window runs independently and occupies the full terminal.
# Create a new window: Ctrl+b c
# Rename current window: Ctrl+b , (type new name, press Enter)
# Switch to window 0: Ctrl+b 0
# Switch to window 1: Ctrl+b 1
# Next/previous: Ctrl+b n / Ctrl+b p
# List windows: Ctrl+b w
# Kill window: Ctrl+b &
The status bar shows all windows. The active window has an asterisk. Renaming windows (Ctrl+b ,) is essential for orientation when a session has 5+ windows.
To move a window to a specific index:
# From the command prompt (Ctrl+b :)
move-window -t 3
swap-window -s 2 -t 4
Pane Management
Panes are where the day-to-day work happens. Split a window, run different commands in each pane, resize as needed.
Splitting
# Vertical split (panes side by side): Ctrl+b %
# Horizontal split (panes stacked): Ctrl+b "
# Split and keep current directory (add to ~/.tmux.conf):
# bind | split-window -h -c "#{pane_current_path}"
# bind - split-window -v -c "#{pane_current_path}"
Resizing Panes
# Fine resize (1 cell at a time): Ctrl+b then hold Ctrl + arrow
# Coarse resize: from command prompt (Ctrl+b :)
resize-pane -D 10 # Down 10 lines
resize-pane -U 10 # Up 10 lines
resize-pane -L 20 # Left 20 columns
resize-pane -R 20 # Right 20 columns
Pane Layouts
Tmux has five built-in layouts you can cycle with Ctrl+b Space:
even-horizontal— panes side by side, equal widtheven-vertical— panes stacked, equal heightmain-horizontal— one large pane on top, smaller panes belowmain-vertical— one large pane on left, smaller panes on righttiled— panes in a grid
Breaking and Joining Panes
# Break a pane out into its own window: Ctrl+b !
# Join a pane from another window into the current window
# (from command prompt: Ctrl+b :)
join-pane -s 2.0 # Move pane 0 from window 2 into current window
join-pane -t 3 # Move current pane into window 3
Copy Mode
Copy mode gives you a full scrollback buffer with search and text selection. It is your less for terminal output.
Entering Copy Mode and Navigating
# Enter copy mode
Ctrl+b [
# Navigate (default emacs bindings)
Arrow keys # Move cursor
Page Up / Page Down # Scroll by page
g # Go to top of buffer
G # Go to bottom of buffer
# Search
/search-term # Search forward
?search-term # Search backward
n # Next match
N # Previous match
# Exit
q
Selecting and Copying (Default Emacs Mode)
Ctrl+Space # Begin selection
Alt+w # Copy selection to tmux buffer
Ctrl+b ] # Paste buffer
Vi Mode (Recommended)
Add to ~/.tmux.conf:
setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
Then in copy mode:
v # Begin selection
y # Yank (copy) selection
Ctrl+b ] # Paste
Copy to System Clipboard
# Linux (requires xclip)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"
# macOS
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
# Over SSH (OSC 52 — works with iTerm2, Windows Terminal, Alacritty)
set -g set-clipboard on
Custom ~/.tmux.conf Configuration
A well-configured ~/.tmux.conf transforms tmux from a tool you tolerate into one you enjoy. Create or open the file:
nano ~/.tmux.conf
Change the Prefix to Ctrl+a
Ctrl+a is on the home row and matches GNU Screen muscle memory:
unbind C-b
set -g prefix C-a
bind C-a send-prefix
Mouse Mode
set -g mouse on
Click to select panes, drag borders to resize, scroll with the mouse wheel.
256-Color and True Color
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
Increase Scrollback Buffer
set -g history-limit 50000
Default is 2000 lines. 50,000 is a reasonable production value. For extremely verbose logs, use 200000.
Vi Keys and Status Bar
# Vi copy mode
setw -g mode-keys vi
# Start windows and panes at 1
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
# No escape delay (critical for vim inside tmux)
set -sg escape-time 0
# Status bar
set -g status-position bottom
set -g status-style "bg=#1a1b26,fg=#a9b1d6"
set -g status-left "#[fg=#06b6d4,bold] #S "
set -g status-left-length 30
set -g status-right "#[fg=#a9b1d6] %Y-%m-%d %H:%M "
setw -g window-status-format " #I:#W "
setw -g window-status-current-format "#[fg=#06b6d4,bold] #I:#W* "
Intuitive Split Bindings
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
Reload Config on the Fly
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
Complete Starter ~/.tmux.conf
# ~/.tmux.conf
# Prefix
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Mouse
set -g mouse on
# Colors
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
# Scrollback
set -g history-limit 50000
# Vi mode
setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Indexing
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
# No escape delay
set -sg escape-time 0
# Split panes
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# Reload
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
# Status bar
set -g status-position bottom
set -g status-style "bg=#1a1b26,fg=#a9b1d6"
set -g status-left "#[fg=#06b6d4,bold] #S "
set -g status-left-length 30
set -g status-right "#[fg=#a9b1d6] %Y-%m-%d %H:%M "
setw -g window-status-format " #I:#W "
setw -g window-status-current-format "#[fg=#06b6d4,bold] #I:#W* "
After saving, reload inside tmux with Ctrl+a r (or Ctrl+b :source-file ~/.tmux.conf before the reload binding takes effect).
Tmux Plugin Manager (tpm) and Essential Plugins
Tpm (tmux plugin manager) makes installing and managing tmux plugins as simple as a few lines in your config.
Installing tpm
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add to the bottom of ~/.tmux.conf:
# Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
# Initialize tpm (keep this line at the very bottom)
run '~/.tmux/plugins/tpm/tpm'
Reload config, then press Ctrl+a I (capital I) to install plugins. Tpm will clone each plugin from GitHub.
tmux-sensible
A set of sensible default options that almost everyone wants. Fixes escape time, increases scrollback, enables focus events, and more. Eliminates the need to configure those individually.
tmux-resurrect
Saves and restores tmux sessions across server reboots.
# Save session
Ctrl+a Ctrl+s
# Restore session (after reboot, before attaching)
Ctrl+a Ctrl+r
Resurrect saves window layouts, pane commands, and working directories. It can also restore vim/neovim sessions if configured.
tmux-continuum
Automatic continuous saving of tmux sessions every 15 minutes (configurable). Works with tmux-resurrect. Optionally restores your last saved session when tmux starts.
# In ~/.tmux.conf
set -g @continuum-restore 'on'
set -g @continuum-save-interval '15'
Updating and Removing Plugins
# Update all plugins: Ctrl+a U
# Remove a plugin: remove the line from .tmux.conf, then Ctrl+a alt+u
Scripting tmux
Tmux’s command-line interface enables scripting complete development environments. Instead of manually splitting panes every morning, run a script.
Sending Commands to Panes
# Create a session and send a command to its first pane
tmux new-session -d -s dev -c ~/projects/api
tmux send-keys -t dev "npm run dev" Enter
Building a 4-Pane Dev Environment
#!/usr/bin/env bash
# dev-environment.sh — start a standard dev session
SESSION="dev"
# Exit if session already exists
tmux has-session -t "$SESSION" 2>/dev/null && tmux attach -t "$SESSION" && exit
# Create session with window "editor"
tmux new-session -d -s "$SESSION" -n "editor" -c ~/projects/api
# Split into 4 panes
tmux split-window -h -t "$SESSION:editor" -c ~/projects/api
tmux split-window -v -t "$SESSION:editor.0" -c ~/projects/api
tmux split-window -v -t "$SESSION:editor.1" -c ~/projects/api
# Arrange in tiled layout
tmux select-layout -t "$SESSION:editor" tiled
# Send commands to each pane
tmux send-keys -t "$SESSION:editor.0" "vim ." Enter
tmux send-keys -t "$SESSION:editor.1" "npm run dev" Enter
tmux send-keys -t "$SESSION:editor.2" "npm run test -- --watch" Enter
tmux send-keys -t "$SESSION:editor.3" "git log --oneline -10" Enter
# Create a logs window
tmux new-window -t "$SESSION" -n "logs" -c ~/projects/api
tmux send-keys -t "$SESSION:logs" "tail -f logs/app.log" Enter
# Focus on editor window, pane 0
tmux select-window -t "$SESSION:editor"
tmux select-pane -t "$SESSION:editor.0"
# Attach
tmux attach -t "$SESSION"
Make executable and run:
chmod +x dev-environment.sh
./dev-environment.sh
Using select-layout for Automated Dashboards
#!/usr/bin/env bash
# monitoring.sh — 4-pane server monitoring dashboard
SESSION="monitor"
tmux new-session -d -s "$SESSION" -n "dashboard"
tmux send-keys -t "$SESSION" "htop" Enter
tmux split-window -h -t "$SESSION"
tmux send-keys -t "$SESSION" "watch -n2 df -h" Enter
tmux split-window -v -t "$SESSION:dashboard.0"
tmux send-keys -t "$SESSION" "tail -f /var/log/syslog" Enter
tmux split-window -v -t "$SESSION:dashboard.1"
tmux send-keys -t "$SESSION" "watch -n5 netstat -tuln" Enter
tmux select-layout -t "$SESSION" tiled
tmux attach -t "$SESSION"
Tmux vs Screen vs Zellij vs Byobu
Choosing the right terminal multiplexer depends on your use case and environment:
| Feature | tmux | GNU Screen | Zellij | Byobu |
|---|---|---|---|---|
| Vertical splits | Built-in | Requires patch | Built-in | Via tmux/screen |
| Configuration syntax | Clean, script-friendly | Complex | YAML/KDL | Simplified tmux |
| Plugin ecosystem | Mature (tpm) | Minimal | Growing | Inherits from tmux |
| Scripting support | Excellent | Limited | Moderate | Limited |
| Performance | Excellent | Excellent | Good | Good |
| Learning curve | Moderate | Moderate | Lower | Lower |
| Session persistence across reboot | Via tmux-resurrect | No | No | Via tmux-resurrect |
| Mouse support | Excellent (v2.1+) | Limited | Excellent | Excellent |
| Active development | Yes | Minimal | Yes (Rust) | Minimal |
| Pre-installed on most servers | Common | Very common | No | No |
| Best for | Power users, DevOps | Legacy systems | New users | Quick start |
Recommendation: Use tmux for production server work and DevOps pipelines. Try Zellij if you want a gentler introduction to terminal multiplexing. Byobu is a good choice if you want tmux with sensible defaults applied automatically.
Practical Workflows
Workflow 1: Long-Running Deployment
You are deploying a database migration that takes 30-45 minutes. You cannot leave your laptop SSH session open.
# Connect to production server
ssh deploy@prod-01.example.com
# Create a deployment session
tmux new -s migration
# Run migration
./scripts/run-migrations.sh
# Detach safely — migration continues
Ctrl+a d
# Disconnect from SSH — migration still running on server
exit
# Hours later, check on it
ssh deploy@prod-01.example.com
tmux attach -t migration
# Migration is either still running or completed
Workflow 2: 4-Pane Development Environment
+---------------------------+---------------------------+
| | |
| Pane 0: vim/code | Pane 1: dev server |
| | npm run dev |
| | |
+---------------------------+---------------------------+
| | |
| Pane 2: test watcher | Pane 3: git / shell |
| npm test -- --watch | |
| | |
+---------------------------+---------------------------+
Use the dev-environment.sh script above to recreate this layout automatically every morning.
Workflow 3: Server Monitoring Dashboard
+---------------------------+---------------------------+
| | |
| Pane 0: htop | Pane 1: df -h (watch) |
| | |
+---------------------------+---------------------------+
| | |
| Pane 2: tail syslog | Pane 3: netstat (watch) |
| | |
+---------------------------+---------------------------+
Attach from any SSH session and instantly have full server visibility. Detach and leave it running. The next engineer who SSHes in can attach and see the same dashboard.
Summary
Tmux solves the two fundamental problems of remote server work: session persistence and terminal organization. Key takeaways:
- Sessions survive SSH drops — detach with
Ctrl+a d, reconnect andtmux attach -t sessionname - Three-level hierarchy — sessions contain windows, windows contain panes
- Prefix key —
Ctrl+bby default,Ctrl+arecommended in~/.tmux.conf - Zoom (
Ctrl+b z) — temporarily full-screens one pane without losing layout - Copy mode (
Ctrl+b [) — scrollback, search, and copy without leaving tmux - tpm plugins — tmux-resurrect saves sessions across reboots, tmux-continuum auto-saves every 15 minutes
- Script everything —
tmux new-session,split-window,send-keys,select-layoutfor reproducible environments
Start with three commands: tmux new -s work, Ctrl+b % to split, and Ctrl+b d to detach. Once reattaching after a disconnect feels natural, the rest follows quickly.