If you have ever lost work because an SSH connection dropped, or found yourself juggling multiple terminal windows to manage a remote server, tmux is the tool that solves both problems. Tmux (short for “terminal multiplexer”) lets you create persistent terminal sessions that survive disconnections, split a single terminal into multiple panes, and switch between entirely separate workspaces — all from one SSH connection. Once you learn tmux, you will wonder how you ever managed without it.
This guide covers everything you need to get productive with tmux: installation, core concepts, session and pane management, custom configuration, copy mode, and pair programming workflows.
Prerequisites
Before starting, you need:
- A Linux system (Ubuntu, Debian, Fedora, CentOS, Arch, or similar)
- Terminal access (local or via SSH)
- Basic familiarity with the command line
- A user account with
sudoprivileges for installation
What Is Tmux?
Tmux is a terminal multiplexer — a program that lets you run multiple terminal sessions inside a single window. It operates on a client-server model: the tmux server runs in the background and manages all sessions, while the tmux client (your terminal) attaches to view and interact with them.
The key benefits of tmux are:
- Persistent sessions — Your work survives SSH disconnections, network drops, and terminal crashes.
- Multiple windows — Switch between separate workspaces (like browser tabs for your terminal).
- Split panes — View and interact with multiple programs side by side in one window.
- Scriptable — Automate complex layouts and workflows via shell scripts.
- Remote collaboration — Multiple users can attach to the same session simultaneously.
Tmux vs GNU Screen
If you have used GNU Screen before, here is how tmux compares:
| Feature | Tmux | GNU Screen |
|---|---|---|
| Vertical splits | Built-in | Requires patch or newer version |
| Configuration | Clean, modern syntax | More complex |
| Scriptability | Excellent | Limited |
| Status bar | Highly customizable | Basic |
| Active development | Yes | Minimal |
| Default on systems | Less common | More common on older systems |
| License | ISC (permissive) | GPL |
Both tools accomplish the same core task: persistent, multiplexed terminal sessions. Tmux is generally the better choice for new users due to its cleaner design and active community. However, if you work on legacy systems where only Screen is available, the core concepts transfer directly.
Installing Tmux
Tmux is available in the default repositories of every major Linux 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 (via Homebrew):
brew install tmux
Verify the installation:
tmux -V
You should see output like tmux 3.4 or similar. Any version 3.0 or later includes all the features covered in this guide.
Core Concepts: Sessions, Windows, and Panes
Understanding the tmux hierarchy is essential before using it effectively. There are three levels:
Session — The top-level container. A session is an independent workspace that can contain multiple windows. You can have many sessions running simultaneously (e.g., one for development, one for deployment, one for monitoring).
Window — A window lives inside a session and occupies the full screen (like a tab in a browser). Each session can have multiple windows, and you switch between them.
Pane — A pane is a subdivision of a window. You can split a window horizontally or vertically to create multiple panes, each running its own shell or command.
tmux server
|
+-- Session: "work"
| +-- Window 0: "editor"
| | +-- Pane 0: vim
| | +-- Pane 1: terminal
| +-- Window 1: "logs"
| +-- Pane 0: tail -f /var/log/syslog
|
+-- Session: "deploy"
+-- Window 0: "main"
+-- Pane 0: ssh production-server
The prefix key is how you tell tmux you are about to issue a command rather than type text. The default prefix is Ctrl+b. You press Ctrl+b, release both keys, then press the command key. For example, Ctrl+b c means: press Ctrl+b, release, then press c to create a new window.
Session Management
Sessions are the foundation of tmux. Here are the essential session commands:
Creating Sessions
# Start a new session with an auto-generated name
tmux
# Start a new named session (recommended)
tmux new -s work
# Start a new session and run a specific command
tmux new -s logs "tail -f /var/log/syslog"
Always name your sessions. When you have multiple sessions running, names make it easy to identify and switch between them.
Detaching from a Session
Press Ctrl+b d to detach from the current session. The session keeps running in the background with all processes intact.
# You can also detach from the command line within tmux
tmux detach
Listing Sessions
# List all running sessions
tmux ls
# Example output:
# deploy: 1 windows (created Mon Jan 20 09:15:22 2026)
# work: 3 windows (created Mon Jan 20 08:30:15 2026) (attached)
Reattaching to a Session
# Attach to the most recent session
tmux attach
# Attach to a specific named session
tmux attach -t work
# Shorthand
tmux a -t work
Killing Sessions
# Kill a specific session
tmux kill-session -t deploy
# Kill all sessions except the current one
tmux kill-session -a
# Kill the tmux server entirely (destroys all sessions)
tmux kill-server
Switching Between Sessions
From within tmux:
Ctrl+b s— List all sessions and select one interactively.Ctrl+b (— Switch to the previous session.Ctrl+b )— Switch to the next session.
Window Management
Windows are like tabs within a session. Each window runs independently and occupies the full terminal area.
Creating and Navigating Windows
# Create a new window
Ctrl+b c
# Rename the current window
Ctrl+b ,
# Switch to window by number
Ctrl+b 0 # Switch to window 0
Ctrl+b 1 # Switch to window 1
# Switch to next/previous window
Ctrl+b n # Next window
Ctrl+b p # Previous window
# List all windows and select interactively
Ctrl+b w
Closing Windows
# Close the current window (close all panes in it)
Ctrl+b &
# Or simply exit the shell running in the window
exit
Tip: The status bar at the bottom shows all windows in the current session. The active window is marked with an asterisk (*). Renaming windows with
Ctrl+b ,helps you keep track of what each window is for.
Pane Management
Panes let you split a single window into multiple terminals. This is one of the most powerful features of tmux.
Splitting Panes
# Split horizontally (top/bottom)
Ctrl+b "
# Split vertically (left/right)
Ctrl+b %
Navigating Between Panes
# Move between panes using arrow keys
Ctrl+b Up
Ctrl+b Down
Ctrl+b Left
Ctrl+b Right
# Cycle through panes
Ctrl+b o
# Jump to a specific pane by number
Ctrl+b q # Shows pane numbers, then press the number
Resizing Panes
# Resize in the direction of the arrow key
# Hold Ctrl+b, then press arrow key repeatedly
Ctrl+b Ctrl+Up
Ctrl+b Ctrl+Down
Ctrl+b Ctrl+Left
Ctrl+b Ctrl+Right
# Or use the resize-pane command
# (within tmux command prompt: Ctrl+b :)
resize-pane -D 5 # Down 5 lines
resize-pane -U 5 # Up 5 lines
resize-pane -L 10 # Left 10 columns
resize-pane -R 10 # Right 10 columns
Pane Layouts and Operations
# Toggle between pane layouts
Ctrl+b Space
# Swap panes
Ctrl+b { # Swap with previous pane
Ctrl+b } # Swap with next pane
# Convert a pane into its own window
Ctrl+b !
# Close the current pane
Ctrl+b x
# Toggle pane zoom (full screen a single pane)
Ctrl+b z
The zoom feature (Ctrl+b z) is particularly useful. It temporarily maximizes one pane to fill the entire window. Press Ctrl+b z again to restore the original layout. This is helpful when you need to focus on one pane briefly without losing your layout.
Customizing tmux.conf
Tmux reads its configuration from ~/.tmux.conf. A well-configured tmux setup dramatically improves usability. Create the file if it does not exist:
touch ~/.tmux.conf
Change the Prefix Key
Many users remap the prefix from Ctrl+b to Ctrl+a (which is closer to the home row and matches GNU Screen):
# Change prefix from Ctrl+b to Ctrl+a
unbind C-b
set -g prefix C-a
bind C-a send-prefix
Enable Mouse Support
Mouse support lets you click to select panes, resize panes by dragging borders, and scroll with the mouse wheel:
# Enable mouse support
set -g mouse on
Improve Colors and Terminal Settings
# Set 256-color terminal
set -g default-terminal "screen-256color"
# Enable true color support
set -ga terminal-overrides ",xterm-256color:Tc"
Customize the Status Bar
# Status bar position
set -g status-position bottom
# Status bar colors
set -g status-style "bg=#1a1b26,fg=#a9b1d6"
# Left side: session name
set -g status-left "#[fg=#06b6d4,bold] #S "
set -g status-left-length 30
# Right side: date and time
set -g status-right "#[fg=#a9b1d6] %Y-%m-%d %H:%M "
# Window status format
setw -g window-status-format " #I:#W "
setw -g window-status-current-format "#[fg=#06b6d4,bold] #I:#W "
Sensible Defaults
# Start window numbering at 1 (not 0)
set -g base-index 1
setw -g pane-base-index 1
# Renumber windows when one is closed
set -g renumber-windows on
# Increase scrollback buffer
set -g history-limit 50000
# Reduce escape time delay (important for vim users)
set -sg escape-time 0
# Reload config file with Ctrl+a r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
Easier Pane Splitting
# Split panes using | and -
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
After editing ~/.tmux.conf, reload it without restarting tmux:
# From within tmux, press Ctrl+b : and type:
source-file ~/.tmux.conf
# Or if you added the binding above:
Ctrl+a r
Complete Example tmux.conf
Here is a full starter configuration combining all the above:
# ~/.tmux.conf - Starter configuration
# Remap prefix to Ctrl+a
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Mouse support
set -g mouse on
# Terminal and colors
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
# Start numbering at 1
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
# Scrollback buffer
set -g history-limit 50000
# No escape delay
set -sg escape-time 0
# Easy split panes
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Easy 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-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 "
Copy Mode and Scrollback
By default, tmux captures terminal output in a scrollback buffer. You can enter copy mode to scroll through previous output, search for text, and copy selections.
Entering and Using Copy Mode
# Enter copy mode
Ctrl+b [
# Navigate in copy mode (vi-style if configured, otherwise emacs-style)
Arrow keys # Move cursor
Page Up # Scroll up one page
Page Down # Scroll down one page
g # Go to top of buffer
G # Go to bottom of buffer
# Search in copy mode
/ # Search forward
? # Search backward
n # Next match
N # Previous match
# Exit copy mode
q
Copying Text
With the default emacs key bindings:
# In copy mode:
Ctrl+Space # Start selection
Alt+w # Copy selection to tmux buffer
# Paste the buffer
Ctrl+b ]
To use vi-style key bindings (recommended for vim users), add to your ~/.tmux.conf:
# Vi copy mode
setw -g mode-keys vi
# Vi-style copy bindings
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
With vi bindings:
# In copy mode:
v # Start selection
y # Yank (copy) selection
# Paste
Ctrl+b ]
Copying to System Clipboard
To integrate tmux’s copy buffer with your system clipboard, install xclip or xsel and add:
# Copy to system clipboard (Linux with xclip)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"
# Copy to system clipboard (macOS)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
Pair Programming with Tmux
One of the most practical uses of tmux is real-time collaboration. When two users attach to the same tmux session, they both see and can interact with the same terminal simultaneously.
Basic Shared Session
# User 1 creates a session on the shared server
tmux new -s pairing
# User 2 SSHs into the same server and attaches
tmux attach -t pairing
Both users now share the same view and can type commands. This is effective but means both users are locked to the same window and pane.
Independent Windows with a Shared Session
For more flexibility, User 2 can create a grouped session that shares the same windows but allows independent viewing:
# User 2 joins with a grouped session
tmux new -s user2 -t pairing
Now both users share the same set of windows, but each can view a different window independently. When they switch to the same window, they see the same content.
Best Practices for Pair Programming
- Name your sessions descriptively so both users know which session to join.
- Communicate about who is typing. Simultaneous input from both users can be confusing.
- Use the zoom feature (
Ctrl+b z) when one user needs to focus on a specific pane. - Set a larger terminal size — tmux resizes to the smallest attached client by default. Use
tmux attach -t pairing -dto detach other clients if screen size is an issue.
Essential Shortcuts Reference Table
Here is a complete reference of the most important tmux shortcuts (using the default Ctrl+b prefix):
| Shortcut | Action |
|---|---|
| Sessions | |
tmux new -s name | Create a new named session |
tmux ls | List all sessions |
tmux attach -t name | Attach to a named session |
tmux kill-session -t name | Kill a named session |
Ctrl+b d | Detach from current session |
Ctrl+b s | List and switch sessions |
Ctrl+b $ | Rename current session |
| Windows | |
Ctrl+b c | Create a new window |
Ctrl+b , | Rename current window |
Ctrl+b n | Next window |
Ctrl+b p | Previous window |
Ctrl+b 0-9 | Switch to window by number |
Ctrl+b w | List and select windows |
Ctrl+b & | Close current window |
| Panes | |
Ctrl+b " | Split pane horizontally |
Ctrl+b % | Split pane vertically |
Ctrl+b Arrow | Navigate between panes |
Ctrl+b o | Cycle through panes |
Ctrl+b z | Toggle pane zoom |
Ctrl+b x | Close current pane |
Ctrl+b ! | Convert pane to window |
Ctrl+b { / } | Swap panes |
Ctrl+b Space | Cycle pane layouts |
| Copy Mode | |
Ctrl+b [ | Enter copy mode |
Ctrl+b ] | Paste buffer |
q | Exit copy mode |
| Other | |
Ctrl+b : | Open command prompt |
Ctrl+b t | Show clock |
Ctrl+b ? | List all key bindings |
Troubleshooting
Tmux Not Found After Installation
If tmux is not found after installing, your shell may need a path refresh:
hash -r
# or start a new shell session
exec bash
Colors Look Wrong Inside Tmux
Ensure your terminal and tmux agree on color support:
# Check your terminal's TERM variable
echo $TERM
# Add to ~/.tmux.conf
set -g default-terminal "screen-256color"
If colors still look off, try:
# Launch tmux with 256 color support explicitly
tmux -2
Nested Tmux Sessions
If you SSH into a server that automatically starts tmux, you may end up with tmux inside tmux. The inner session captures the prefix key, making it impossible to control the outer session.
Solution: Use a different prefix for the inner session, or send the prefix key to the inner session by pressing the prefix twice:
# Send prefix to inner tmux session
Ctrl+b Ctrl+b
Mouse Scroll Not Working
If mouse scrolling does not work, ensure mouse mode is enabled:
# In ~/.tmux.conf
set -g mouse on
Then reload the configuration. If using an older version of tmux (before 2.1), the mouse options are different:
# For tmux versions before 2.1
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
Session Disappeared After Reboot
Tmux sessions do not survive a system reboot by default. The tmux server process runs in memory. If the server restarts, all sessions are lost.
To persist sessions across reboots, use the tmux-resurrect plugin:
# Install tmux plugin manager (TPM)
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# Add to ~/.tmux.conf
set -g @plugin 'tmux-plugins/tmux-resurrect'
run '~/.tmux/plugins/tpm/tpm'
# Save session: Ctrl+b Ctrl+s
# Restore session: Ctrl+b Ctrl+r
Clipboard Integration Not Working Over SSH
When using tmux over SSH, copying to your local clipboard requires extra setup. Use SSH with X11 forwarding or configure OSC 52 escape sequences:
# Enable OSC 52 clipboard in tmux.conf
set -g set-clipboard on
Your terminal emulator must also support OSC 52 (most modern terminals do, including iTerm2, Alacritty, and Windows Terminal).
Summary
Tmux is an essential tool for anyone who works with remote servers or wants a more efficient terminal workflow. Its persistent sessions protect you from connection drops, its window and pane management lets you organize complex tasks, and its scripting capabilities enable reproducible development environments.
The key takeaways from this guide:
- Sessions persist even when your SSH connection drops — just
tmux attachto resume. - Windows and panes let you organize multiple tasks within a single terminal.
- Custom configuration via
~/.tmux.confmakes tmux fit your workflow perfectly. - Copy mode gives you full scrollback and search capabilities.
- Pair programming is as simple as two users attaching to the same session.
Start with the basics: create a named session, split a few panes, detach, and reattach. As the shortcuts become muscle memory, you will find yourself naturally building more complex workflows.
Tmux pairs well with a secure server setup. If you have not already hardened your SSH configuration, read our guide on SSH Hardening: 12 Steps to Secure Your Linux Server. For a broader server security overview, see the Linux Server Security Checklist: 20 Essential Steps.