tmux Complete Guide: Terminal Multiplexer for Linux

✅ Tested on Ubuntu 24.04, Debian 12, Arch Linux — Last updated: June 2026
tmux is a terminal multiplexer that lets you run multiple terminal sessions inside a single window, detach from them, and come back later without losing any work. Once you start using tmux, you'll wonder how you ever lived without it — especially for SSH sessions, long-running processes, and development workflows that need multiple panels side by side.
This guide covers everything from installation to advanced workflows, with all the shortcuts you'll actually use.
Table of Contents
- Install tmux
- Core Concepts: Sessions, Windows, Panes
- Starting and Using tmux
- Working with Panes
- Working with Windows
- Session Management
- tmux Configuration (~/.tmux.conf)
- Copy Mode and Scrolling
- tmux Plugin Manager
- Real Workflows
- Troubleshooting
- Quick Reference Cheat Sheet
Install tmux
# Ubuntu / Debian / Linux Mint:
sudo apt install tmux -y
# Fedora:
sudo dnf install tmux -y
# Arch Linux:
sudo pacman -S tmux
# Check version:
tmux -V
# tmux 3.4Core Concepts: Sessions, Windows, Panes
Before diving into commands, understand the three-level hierarchy:
- Session: A container for one or more windows. You can detach from a session and it keeps running. Sessions survive SSH disconnections.
- Window: A full-screen view within a session. Like tabs in a browser — you can switch between them.
- Pane: A subdivision of a window. You can split a window into multiple panes, each running an independent shell.
Visual hierarchy:
Session: "development"
├── Window 1: "editor" ← vim on the left, logs on the right
│ ├── Pane 1: vim
│ └── Pane 2: tail -f app.log
├── Window 2: "server" ← running the dev server
│ └── Pane 1: npm start
└── Window 3: "git" ← git operations
└── Pane 1: bashStarting and Using tmux
The Prefix Key
Every tmux command starts with a prefix key. The default is Ctrl+B. Press the prefix, release it, then press the command key.
Ctrl+B then ? ← shows all key bindings (press q to quit)Start, Attach, Detach
# Start a new session (anonymous):
tmux
# Start a named session (recommended):
tmux new -s mysession
tmux new-session -s mysession # same thing
# Detach from current session:
Ctrl+B then D
# List sessions:
tmux ls
tmux list-sessions
# Attach to a session:
tmux attach -t mysession
tmux a -t mysession # shorthand
# Attach to most recent session:
tmux a
# Kill a session:
tmux kill-session -t mysession
# Kill ALL sessions (nuclear option):
tmux kill-serverWorking with Panes
Panes let you see multiple terminals simultaneously. This is where tmux becomes a superpower.
# Split horizontally (panes side by side):
Ctrl+B then %
# Split vertically (panes top and bottom):
Ctrl+B then "
# Navigate between panes:
Ctrl+B then ← → ↑ ↓ (arrow keys)
Ctrl+B then o (cycle through panes)
Ctrl+B then ; (go to last active pane)
# Resize panes:
Ctrl+B then Ctrl+← → ↑ ↓ (hold Ctrl while pressing arrows to resize)
# Zoom in on current pane (full screen):
Ctrl+B then Z (press again to zoom out)
# Swap pane positions:
Ctrl+B then { (move pane left/up)
Ctrl+B then } (move pane right/down)
# Convert pane to window:
Ctrl+B then !
# Close current pane:
Ctrl+B then X (confirm with y)
# Or just type: exitPane Layouts
tmux has built-in layouts you can cycle through:
Ctrl+B then Space ← cycle through: even-horizontal, even-vertical, main-horizontal, main-vertical, tiledWorking with Windows
Windows in tmux are like browser tabs. Each window has its own layout of panes.
# Create a new window:
Ctrl+B then C
# Rename current window:
Ctrl+B then ,
# Switch between windows:
Ctrl+B then N (next window)
Ctrl+B then P (previous window)
Ctrl+B then 0-9 (go to window by number)
Ctrl+B then L (last used window)
# List windows (interactive picker):
Ctrl+B then W
# Close current window:
Ctrl+B then & (confirm with y)Session Management
# List sessions (interactive):
Ctrl+B then S
# Rename current session:
Ctrl+B then $
# Switch to another session:
Ctrl+B then ( (previous session)
Ctrl+B then ) (next session)
# From command line — create and switch to session:
tmux new -s newsession -d # create in background
tmux switch -t newsession # switch to ittmux Configuration (~/.tmux.conf)
The default tmux configuration is functional but not ideal. Here's a solid config that most developers use:
nano ~/.tmux.conf# ~/.tmux.conf — A practical tmux configuration
# Change prefix from Ctrl+B to Ctrl+A (like screen, easier to type)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Split panes with | and - (more intuitive than % and ")
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# Open new windows in current directory
bind c new-window -c "#{pane_current_path}"
# Reload config:
bind r source-file ~/.tmux.conf ; display "Config reloaded!"
# Navigate panes with vim keys (h/j/k/l)
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Resize panes with Shift+arrow
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# Enable mouse support (click to select pane, drag to resize)
set -g mouse on
# Start numbering at 1 (easier to reach than 0 on keyboard)
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on
# Increase scrollback buffer
set -g history-limit 50000
# Faster key repetition
set -s escape-time 0
# Enable 256 colors
set -g default-terminal "screen-256color"
set-option -sa terminal-overrides ",xterm*:Tc"
# Status bar improvements
set -g status-position bottom
set -g status-style bg=colour235,fg=colour255
set -g status-left '#[fg=colour82,bold] #S '
set -g status-right '#[fg=colour255]%Y-%m-%d #[fg=colour82]%H:%M '
set -g status-right-length 50
set -g window-status-current-style bg=colour82,fg=colour235,bold# Apply the config without restarting:
tmux source ~/.tmux.conf
# Or with the new bind: Ctrl+A then RCopy Mode and Scrolling
tmux has a copy mode for scrolling through terminal history and selecting text:
# Enter copy mode:
Ctrl+B then [ (or Ctrl+A then [ with the config above)
# In copy mode:
↑ / ↓ / PgUp / PgDn scroll through history
/ search forward
? search backward
n next search match
N previous match
# Select text (default mode):
Space start selection
Enter copy selection and exit copy mode
# Vim-style copy mode (add to .tmux.conf):
set-window-option -g mode-keys vi
# Then in copy mode:
v start selection (like vim visual mode)
y yank (copy)
Ctrl+V block selection
# Paste:
Ctrl+B then ]tmux Plugin Manager (TPM)
TPM makes installing and managing tmux plugins easy. The most popular plugins:
# Install TPM:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# Add to ~/.tmux.conf:
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible' # sensible defaults
set -g @plugin 'tmux-plugins/tmux-resurrect' # save/restore sessions
set -g @plugin 'tmux-plugins/tmux-continuum' # auto-save sessions
set -g @plugin 'tmux-plugins/tmux-yank' # copy to system clipboard
# Initialize TPM (keep this at the bottom of .tmux.conf):
run '~/.tmux/plugins/tpm/tpm'# Install plugins:
Ctrl+B then I (capital I — install)
# Update plugins:
Ctrl+B then U
# Uninstall removed plugins:
Ctrl+B then Alt+UReal Workflows
Development Workflow
tmux new -s dev
# Window 1: Code editor
# Run your editor here
nvim .
# Create window 2 for the dev server:
Ctrl+A then C (or Ctrl+B then C)
# rename it:
Ctrl+A then ,
# name: server
npm run dev
# Create window 3 for git:
Ctrl+A then C
Ctrl+A then ,
# name: git
# Split window 3 for multiple git panes:
Ctrl+A then - (split horizontal)
# top: git status/log
# bottom: git commit, push, etc.Server Monitoring Workflow
tmux new -s monitoring
# Split into 4 panes (tiled layout):
# Top left:
htop
# Split right:
Ctrl+A then |
# Top right:
watch -n 5 df -h
# Split bottom left:
Ctrl+A then -
# Bottom left:
tail -f /var/log/nginx/access.log
# Split bottom right:
Ctrl+A then |
# Bottom right:
journalctl -f -u myserviceLong-Running Tasks on a Remote Server
# Connect to server:
ssh user@server
# Start a named tmux session:
tmux new -s training
# Run your long job:
python train_model.py --epochs 100
# Detach (your training continues):
Ctrl+A then D
# Disconnect from SSH — training still running
# Next day, reconnect:
ssh user@server
tmux attach -t training
# Your training output is right thereScript to Create Your Default Environment
#!/bin/bash
# ~/bin/devenv — creates my standard dev layout
SESSION="dev"
# Don't create if already exists
tmux has-session -t $SESSION 2>/dev/null && tmux attach -t $SESSION && exit
tmux new-session -d -s $SESSION -n "code"
tmux send-keys -t $SESSION:0 "cd ~/projects && nvim ." Enter
tmux new-window -t $SESSION -n "server"
tmux send-keys -t $SESSION:1 "cd ~/projects" Enter
tmux new-window -t $SESSION -n "git"
tmux send-keys -t $SESSION:2 "cd ~/projects && git status" Enter
tmux select-window -t $SESSION:0
tmux attach -t $SESSIONchmod +x ~/bin/devenv
devenv # one command to set up your full workspaceTroubleshooting
Prefix key not working
Make sure you press and release the prefix before the command key. Common mistake: holding Ctrl+B while pressing another key (that's not how it works). The flow is: press Ctrl+B → release → press command key.
Colors look wrong in tmux
# Add to ~/.tmux.conf:
set -g default-terminal "screen-256color"
set-option -sa terminal-overrides ",xterm*:Tc"
# Also set in your shell:
export TERM=xterm-256colorMouse scroll not working
# Enable mouse in .tmux.conf:
set -g mouse on
# After adding, reload:
tmux source ~/.tmux.confClipboard not working (can't paste from tmux to external apps)
# Install xclip or xsel:
sudo apt install xclip
# Install tmux-yank plugin (see Plugins section)
# Or manually add to .tmux.conf:
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'Quick Reference Cheat Sheet
Using the default prefix Ctrl+B (replace with Ctrl+A if you changed it):
| Action | Key |
|---|---|
| Detach from session | Ctrl+B D |
| List sessions (interactive) | Ctrl+B S |
| New window | Ctrl+B C |
| Next / Previous window | Ctrl+B N / P |
| Switch to window N | Ctrl+B 0-9 |
| Rename window | Ctrl+B , |
| Split vertical (side by side) | Ctrl+B % |
| Split horizontal (top/bottom) | Ctrl+B " |
| Navigate panes | Ctrl+B ← → ↑ ↓ |
| Zoom current pane | Ctrl+B Z |
| Close pane | Ctrl+B X |
| Enter copy mode | Ctrl+B [ |
| Paste | Ctrl+B ] |
| Show all keybindings | Ctrl+B ? |
Frequently Asked Questions
tmux vs. screen — which should I use?
tmux. Screen is older and less actively maintained. tmux has better split panes, better scripting, a more modern configuration system, and a richer plugin ecosystem. The only reason to use screen today is if it's already in place on systems you don't control.
Does tmux work over SSH?
Yes, and that's one of its best use cases. Start tmux on the remote server, run your work, detach with Ctrl+B D, disconnect from SSH, and reconnect later. Your session and all running processes are exactly where you left them.
Can I have tmux start automatically when I SSH in?
# Add to ~/.bashrc or ~/.zshrc on the server:
if [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
tmux attach -t main 2>/dev/null || tmux new -s main
fiWhat happens to tmux sessions when the server reboots?
Sessions are lost on reboot. Use tmux-resurrect plugin with tmux-continuum to automatically save and restore sessions across reboots. Running processes (like training jobs) are still lost, but the session layout and window names are restored.
tmux fundamentally changes how you work in the terminal. Pair it with a solid command line knowledge and you have a development environment that matches or exceeds most graphical IDEs for server work.
