Working remotely over SSH or running long-running compilation and backup jobs on a headless Linux server carries an ever-present risk: an unstable Wi-Fi connection, VPN hiccup, or accidental terminal closure instantly kills the active shell session, aborting whatever critical process was underway. tmux (Terminal Multiplexer) solves this fundamental limitation. By decoupling terminal processes from the graphical emulator or remote SSH connection, tmux allows you to create persistent background sessions, split a single console into multiple interactive panes, and seamlessly reconnect from any machine at any time.
What Is tmux and How Does It Operate?
tmux operates on a client-server architecture. When you invoke tmux, a lightweight daemon launches in the system background and manages your virtual terminal sessions. Your visible command-line window acts merely as a client attached to that server. If the network connection drops or you detach manually, the server continues running all sub-processes completely uninterrupted.
tmux structures its workspace into three hierarchical levels:
- Sessions: Self-contained container environments that survive disconnects and reboot cycles (until server restart).
- Windows: Virtual tabs within a session, allowing you to toggle between full-screen console views.
- Panes: Subdivisions within a single window, enabling side-by-side vertical and horizontal multi-tasking.
Installing tmux Across Linux Distributions
tmux is available in the official package repositories of all major Linux distributions. Install it using your system’s package manager:
On Debian, Ubuntu, and Linux Mint:
sudo apt update
sudo apt install tmux -y
On Fedora, RHEL, and AlmaLinux:
sudo dnf install tmux -y
On Arch Linux and Manjaro:
sudo pacman -S tmux
Creating and Naming Persistent tmux Sessions
Starting an unnamed session is as simple as entering tmux, but assigning descriptive labels prevents confusion when managing multiple production tasks simultaneously.
To create a session with an explicit name:
tmux new -s maintenance
To safely detach from an active session without terminating running scripts, press the default prefix key combination followed by d:
Ctrl + b, then press d
To list all active tmux sessions currently running on the server:
tmux ls
To reattach to your previously detached session:
tmux attach -t maintenance
Mastering Split Panes and Navigation
tmux uses a leader prefix key sequence—by default, Ctrl + b—to tell the multiplexer that your next keystroke is a command rather than plain shell input. Release both keys, then strike the action key.
Essential pane control key combinations include:
- Split Vertically (side by side): Press
Ctrl + b, then press% - Split Horizontally (top and bottom): Press
Ctrl + b, then press" - Navigate Between Panes: Press
Ctrl + b, then use theArrow Keys(Up, Down, Left, Right) - Toggle Pane Zoom (fullscreen): Press
Ctrl + b, then pressz(press again to restore original size) - Close Active Pane: Type
exitor pressCtrl + d
Essential tmux Keybindings Reference
| Action | Key Combination | Description |
|---|---|---|
| Prefix Leader | Ctrl + b |
Precedes all multiplexer commands |
| Detach Session | Ctrl + b, d |
Leaves session running safely in background |
| Split Horizontal | Ctrl + b, " |
Divides current pane into top and bottom halves |
| Split Vertical | Ctrl + b, % |
Divides current pane into left and right columns |
| Create Window | Ctrl + b, c |
Spawns a fresh full-screen tab |
| Switch Window | Ctrl + b, [0-9] |
Jumps directly to the designated window index |
| Zoom Pane | Ctrl + b, z |
Toggles magnification of current pane |
| Enter Scroll Mode | Ctrl + b, [ |
Allows scrolling terminal output with arrow keys; press q to exit |
Configuring Quality-of-Life Improvements in .tmux.conf
Customise your tmux experience by creating a configuration file at ~/.tmux.conf to enable mouse scrolling and modern colouring:
cat << 'EOF' > ~/.tmux.conf
# Enable mouse support for clicking panes and scrolling
set -g mouse on
# Set 256 colour mode
set -g default-terminal "screen-256color"
# Increase scrollback buffer history
set -g history-limit 10000
EOF
Reload your configuration instantly within an active session by pressing Ctrl + b, typing :source-file ~/.tmux.conf, and pressing Enter.
Frequently Asked Questions
What is the difference between tmux and nohup?
While nohup prevents a single command from dying upon logout, it redirects output to a static log file and provides no interactivity. tmux provides full, interactive terminal control, multi-pane navigation, and the ability to reattach exactly where you left off.
Do tmux sessions persist across system reboots?
Standard tmux sessions reside in RAM and terminate if the operating system reboots. To preserve tmux sessions across reboots, use plugins such as tmux-resurrect and tmux-continuum via the Tmux Plugin Manager (TPM).
How do I completely kill an unwanted tmux session from the command line?
Run tmux kill-session -t [session_name] to terminate the specified session and all its associated processes.