Terminal multiplexing solves one of the most common problems in server administration: when your SSH connection drops mid-task, any running process in that session is killed. With tmux, your terminal sessions run inside a server-side process that persists independently of your SSH connection. You can detach from a session, disconnect, reconnect hours later from a different machine, and reattach to find everything exactly as you left it — commands still running, output still in the scrollback buffer, windows and panes still arranged. For long-running operations like database migrations, log tailing, and system updates, tmux is indispensable.
Beyond session persistence, tmux provides a complete window and pane management system: split the terminal vertically or horizontally into independent panes, switch between multiple windows (like browser tabs), share a session with a colleague in real time for pair-debugging, and write custom keybindings and status bar configurations. This guide covers installing and configuring tmux on RHEL 9, all essential keybindings, custom configuration, session sharing, and scripted session creation.
Prerequisites
- RHEL 9 server with root or sudo access
- SSH client capable of reconnecting
Step 1 — Install tmux
dnf install -y tmux
Verify the installation:
tmux -V
Step 2 — Basic Session Management
# Start a new session
tmux
# Start a named session (recommended — easier to reattach)
tmux new-session -s main
# Detach from the current session (stays running in background)
# Press: Ctrl+b then d
# List all sessions
tmux list-sessions
# or short form:
tmux ls
# Reattach to the most recent session
tmux attach
# Reattach to a named session
tmux attach -t main
# Kill a session
tmux kill-session -t main
# Kill all sessions
tmux kill-server
Step 3 — Understanding the Prefix Key
All tmux keybindings start with a prefix key, which is Ctrl+b by default. Press the prefix, release, then press the next key. For example: Ctrl+b d means press Ctrl+b, release both keys, then press d.
Essential keybindings:
Ctrl+b d— detach from sessionCtrl+b ?— show all keybindingsCtrl+b :— open the tmux command promptCtrl+b [— enter copy mode (scroll, search, copy text)Ctrl+b ]— paste buffer
Step 4 — Window Management
Windows are like browser tabs — each window runs its own shell or command:
Ctrl+b c # Create a new window
Ctrl+b , # Rename the current window
Ctrl+b n # Next window
Ctrl+b p # Previous window
Ctrl+b 0-9 # Switch to window by number
Ctrl+b w # Show window list (interactive chooser)
Ctrl+b & # Kill the current window (with confirmation)
Step 5 — Pane Management
Panes split a window into multiple independent terminal regions:
Ctrl+b % # Split pane vertically (left/right)
Ctrl+b " # Split pane horizontally (top/bottom)
Ctrl+b → # Move to pane on the right (use arrow keys)
Ctrl+b ← # Move to pane on the left
Ctrl+b ↑ # Move to pane above
Ctrl+b ↓ # Move to pane below
Ctrl+b o # Cycle through panes
Ctrl+b q # Show pane numbers briefly (press the number to jump)
Ctrl+b z # Zoom/unzoom current pane (toggle fullscreen)
Ctrl+b x # Kill the current pane (with confirmation)
Ctrl+b { # Swap pane with the previous one
Ctrl+b } # Swap pane with the next one
Ctrl+b Space # Cycle through layout presets (even-horizontal, tiled, etc.)
Resize panes:
Ctrl+b : resize-pane -D 5 # Resize down by 5 lines
Ctrl+b : resize-pane -U 5 # Resize up by 5 lines
Ctrl+b : resize-pane -L 5 # Resize left by 5 columns
Ctrl+b : resize-pane -R 5 # Resize right by 5 columns
Step 6 — Copy Mode for Scrollback and Searching
Ctrl+b [ # Enter copy mode
q or Escape # Exit copy mode
# In copy mode:
/ # Search forward
? # Search backward
n # Next match
N # Previous match
Space # Start selection (vi mode) or Enter (emacs mode)
Enter # Copy selection and exit copy mode
g # Jump to top of scrollback buffer
G # Jump to bottom
Step 7 — Create a ~/.tmux.conf Configuration File
The configuration file at ~/.tmux.conf is read on startup:
vi ~/.tmux.conf
# Change prefix from Ctrl+b to Ctrl+a (like GNU Screen)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Reload config with prefix + r
bind r source-file ~/.tmux.conf ; display-message "Config reloaded!"
# Split panes with | and - (more intuitive)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# Switch panes with Alt+arrow keys (no prefix needed)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# Enable mouse support (click to select panes/windows, resize panes)
set -g mouse on
# Increase scrollback buffer size
set -g history-limit 50000
# Start window numbering at 1 (easier to reach than 0)
set -g base-index 1
setw -g pane-base-index 1
# Renumber windows when one is closed
set -g renumber-windows on
# Display messages for longer
set -g display-time 3000
# Use vi keys in copy mode
setw -g mode-keys vi
# Better copy-paste (requires xclip on systems with X11)
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Status bar
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-left '#[fg=colour233,bg=colour241,bold] #S '
set -g status-right '#[fg=colour233,bg=colour241,bold] %Y-%m-%d %H:%M '
set -g status-right-length 50
set -g status-left-length 20
setw -g window-status-current-format '#[fg=colour81,bg=colour238,bold] #I:#W '
setw -g window-status-format '#[fg=colour138,bg=colour235] #I:#W '
Step 8 — Create Scripted Sessions
For development or operations workflows, automate your tmux session layout with a shell script:
vi ~/bin/dev-session.sh
#!/bin/bash
SESSION="devops"
# Create session with first window
tmux new-session -d -s $SESSION -n 'editor'
# Open editor in first window
tmux send-keys -t $SESSION:editor 'vim .' Enter
# Create second window for running the app
tmux new-window -t $SESSION -n 'server'
tmux send-keys -t $SESSION:server 'cd /opt/myapp && ./start.sh' Enter
# Create third window for logs
tmux new-window -t $SESSION -n 'logs'
tmux send-keys -t $SESSION:logs 'sudo journalctl -fu myapp' Enter
# Split logs window to also show nginx logs
tmux split-window -t $SESSION:logs -v
tmux send-keys -t $SESSION:logs.2 'sudo tail -f /var/log/nginx/access.log' Enter
# Go back to the editor window
tmux select-window -t $SESSION:editor
# Attach
tmux attach -t $SESSION
chmod +x ~/bin/dev-session.sh
~/bin/dev-session.sh
Step 9 — Share a Session for Pair Debugging
# On the server, create a shared session
tmux new-session -s shared
# Colleague attaches to the same session (same view, both can type)
tmux attach -t shared
# Or create a separate grouped session (each can navigate windows independently)
tmux new-session -t shared -s colleague
Verification Checklist
# Confirm tmux is running
tmux ls
# Show current session info from inside tmux
tmux display-message "Session: #S, Window: #W, Pane: #P"
# List all keybindings
tmux list-keys
Conclusion
You now have a fully configured tmux environment on RHEL 9 with a custom prefix key, intuitive split-pane bindings, mouse support, and a scripted session that creates your standard working layout automatically. Your long-running processes are now resilient to SSH disconnections, and you can share debugging sessions with colleagues in real time.
Next steps: How to Configure Log Rotation with logrotate on RHEL 9, How to Use journalctl for Systemd Log Analysis on RHEL 9, and How to Set Up a Bash Profile and Environment Variables on RHEL 9.