Using tmux for Persistent Terminal Sessions
tmux is a terminal multiplexer that keeps your sessions alive after SSH disconnects — essential for long-running tasks on a server.
Install tmux
apt install tmux -y # Ubuntu/Debian
dnf install tmux -y # CentOS/RHEL
Start a New Session
tmux new -s mysession
Detach from a Session (Session Stays Running)
Press Ctrl+B then D
List Sessions
tmux ls
Reattach to a Session
tmux attach -t mysession
Kill a Session
tmux kill-session -t mysession
Key Shortcuts (all preceded by Ctrl+B)
- Ctrl+B % — split pane vertically
- Ctrl+B " — split pane horizontally
- Ctrl+B arrow — move between panes
- Ctrl+B c — create new window
- Ctrl+B n — next window
- Ctrl+B p — previous window
- Ctrl+B & — kill current window
- Ctrl+B [ — enter scroll/copy mode (use arrow keys, q to exit)
Basic ~/.tmux.conf
# Enable mouse support
set -g mouse on
# Increase scrollback buffer
set -g history-limit 10000
# Start windows at 1
set -g base-index 1
Reload config: tmux source-file ~/.tmux.conf