How to Use the tmux Terminal Multiplexer in Linux for Persistent Sessions

System administrators, cloud developers, and engineers working over remote SSH connections frequently encounter a precarious problem: if your Wi-Fi drops, your laptop battery dies, or your VPN connection disconnects midway through a long-running software build or database migration, the remote terminal session is terminated and your background process is abruptly killed. Furthermore, managing multiple shell tasks simultaneously often leads to dozens of cluttered terminal emulator windows across your desktop. To provide indestructible session persistence and versatile screen partitioning, Linux relies on tmux (Terminal Multiplexer). With tmux, processes run safely inside persistent background server sessions that survive SSH disconnects, complete with versatile window and pane management.

How tmux Works Under the Linux Kernel

The architecture of tmux separates the terminal client from the shell processes:

  • Client-Server Separation: When you start tmux, it launches a background daemon server process. Shell instances (windows and panes) execute under this server process rather than your local SSH connection. If your SSH client drops, the tmux server and all child processes continue running uninterrupted.
  • Detachable Sessions: You can disconnect (detach) from an active tmux session, close your computer, travel to another location, reconnect via SSH from a different machine, and reattach to the exact session with all output buffers and running programs preserved.
  • Panes and Windows: A single terminal window can be subdivided into multiple panes horizontally or vertically, and organized across multiple virtual tabs (windows).
  • Keyboard-Driven Control: Almost all tmux operations are orchestrated via a universal prefix key combination (default: Ctrl + b) followed by a command key.

Installing tmux on Major Linux Distributions

tmux is available across official software repositories on all primary Linux distributions:

On Ubuntu, Debian, and Linux Mint:

sudo apt update
sudo apt install tmux -y

On Fedora, RHEL, CentOS, and AlmaLinux:

sudo dnf install tmux -y

On Arch Linux and Manjaro:

sudo pacman -S tmux

Starting and Naming tmux Sessions

To avoid losing track of what tasks are running inside each session, always create named sessions instead of default numbered ones:

1. Creating a New Named Session

tmux new -s dev_environment

A green status bar immediately appears across the bottom of your terminal window indicating that tmux is active.

2. Listing Active Sessions

tmux ls

3. Attaching to an Existing Session

tmux attach -t dev_environment

4. Killing an Obsolete Session

tmux kill-session -t dev_environment

Essential Window and Pane Keybindings (Ctrl + b Prefix)

To execute commands inside tmux, press the prefix combination Ctrl + b, release both keys, and then press the specific action key:

Splitting the Screen into Panes

  • Horizontal Split: Press Ctrl + b, then " (double quote). Splits the current pane into top and bottom halves.
  • Vertical Split: Press Ctrl + b, then % (percent sign). Splits the current pane into left and right halves.
  • Navigate Between Panes: Press Ctrl + b, then press any Arrow Key (Up, Down, Left, Right).
  • Close Active Pane: Type exit or press Ctrl + d.
  • Toggle Pane Zoom: Press Ctrl + b, then z. Maximizes the current pane to full screen; pressing it again restores the split layout.

Managing Virtual Windows (Tabs)

  • Create New Window: Press Ctrl + b, then c.
  • Switch to Next Window: Press Ctrl + b, then n.
  • Switch to Previous Window: Press Ctrl + b, then p.
  • Switch to Window by Number: Press Ctrl + b, then 0–9.
  • Rename Current Window: Press Ctrl + b, then , (comma).

Detaching from a Running Session Without Killing Tasks

When executing a long-running process (like an OS update or model training):

  1. Launch your command inside the tmux session (e.g., sudo apt full-upgrade).
  2. Press Ctrl + b, then press d.
  3. tmux detaches immediately, returning you to your standard host shell prompt with the message: [detached (from session dev_environment)].
  4. You can now safely close your terminal, terminate your SSH connection, or shut down your local computer.
  5. When you log back into the server later, run tmux attach -t dev_environment to find your process still running exactly where you left it.

Enabling Mouse Support and Custom Configuration (~/.tmux.conf)

By default, tmux requires keyboard shortcuts to select panes or resize windows. You can enable intuitive mouse controls (clicking to focus panes, dragging borders to resize, and mouse wheel scrolling) by adding a few lines to your user configuration file:

nano ~/.tmux.conf

Add the following configuration lines:

# Enable full mouse control
set -g mouse on

# Increase scrollback buffer history limit
set -g history-limit 10000

# Set 256 colour terminal support
set -g default-terminal "screen-256color"

Save the file and reload the configuration inside tmux by pressing Ctrl + b, typing :source-file ~/.tmux.conf, and pressing Enter.

tmux vs GNU Screen Comparison

Feature tmux GNU Screen
Development & Maintenance Actively developed and modernised Legacy (slower release cadence)
Default Prefix Key Ctrl + b Ctrl + a
Vertical & Horizontal Pane Splits Native, fluid, and robust Complex layout persistence
Configuration Syntax Clean, readable, well-documented Cryptic legacy syntax
Status Bar Customisation Highly scriptable, colourful, extensible Basic monochrome formatting

Frequently Asked Questions

How do I scroll up through past output in a tmux pane?

Press Ctrl + b, then [ (left square bracket) to enter copy/scroll mode. Use your arrow keys or Page Up/Page Down to browse historical output. Press q to exit scroll mode. If you have enabled set -g mouse on, you can simply use your mouse scroll wheel.

Can multiple team members join the same tmux session simultaneously?

Yes. If two users connect to the same Linux server under the same account and run tmux attach -t session_name, both users see the same screen and can collaborate or pair-programme in real time.

What happens to tmux sessions if the server reboots?

Because tmux server processes run in RAM, a physical server reboot or power failure terminates all sessions. To save and restore tmux layouts across reboots, use plugins like tmux-resurrect.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.