Start a long process on a server and disconnect from SSH — the process keeps running. Come back an hour later, reconnect to the same session, and see everything exactly as you left it. That is what tmux is for. But between 'create a session' and 'manage sessions efficiently' lies a whole set of commands worth knowing.
Installation
Debian / Ubuntu:
sudo apt install tmux
RHEL / CentOS / Rocky:
sudo dnf install tmux
Arch Linux:
sudo pacman -S tmux
Check version:
tmux -V
Create a Session
Start tmux without a name — the session gets a number:
tmux
Start with a name — easier when multiple sessions are running:
tmux new -s myproject
Meaningful names like backend, logs, deploy work better than numbers when you have five sessions open.
Create a session and immediately run a command inside it:
tmux new -s monitoring -d "htop"
The -d flag creates the session in the background — does not switch to it immediately.
List Running Sessions
tmux ls
Shows name, number of open windows, and creation time for each session.
Attach to a Session
By name:
tmux attach -t myproject
By number:
tmux attach -t 0
If only one session is running — the name can be omitted:
tmux attach
Attach to the most recently used session:
tmux attach -t $(tmux ls | tail -1 | cut -d: -f1)
Detach From a Session
Leave the session running and return to the regular terminal — keyboard shortcut inside tmux:
Ctrl+b d
Press Ctrl+b, release, then press d. The session keeps running in the background, all processes inside stay alive.
Detach another user from a session without leaving it yourself:
tmux detach-client -t myproject
Rename a Session
From outside tmux:
tmux rename-session -t old_name new_name
Inside the active session — keyboard shortcut:
Ctrl+b $
An input prompt appears, type the new name and press Enter.
Kill a Session
From the command line outside tmux:
tmux kill-session -t myproject
From inside the active session:
Ctrl+b :kill-session
Kill all sessions at once:
tmux kill-server
Multiple Windows Inside One Session
A session is a container for windows. One session, several windows — each in its own tab.
Create a new window inside the session:
Ctrl+b c
Switch between windows:
Ctrl+b n — next
Ctrl+b p — previous
Ctrl+b 0 — by number (0-9)
Show window list:
Ctrl+b w
Close the current window:
Ctrl+b &
Split a Window Into Panes
A window can be split into multiple panes — separate terminals on the same screen.
Split horizontally (one above the other):
Ctrl+b "
Split vertically (side by side):
Ctrl+b %
Navigate between panes:
Ctrl+b arrow keys
Close the current pane:
Ctrl+b x
Share a Session With Another User
tmux allows multiple users to attach to the same session — useful for pair programming or remote assistance. Both see the same screen in real time.
First user creates the session:
tmux new -s shared
Second user attaches:
tmux attach -t shared
Both control the terminal simultaneously — both see all output.
~/.tmux.conf: Basic Configuration
Change the prefix from Ctrl+b to Ctrl+a — easier on the fingers during long sessions:
set-option -g prefix C-a
unbind C-b
bind C-a send-prefix
Number windows from 1 instead of 0 — matches keyboard layout more naturally:
set -g base-index 1
Enable mouse support and increase command history:
set -g mouse on
set -g history-limit 10000
Apply changes without restarting tmux — inside a session:
Ctrl+b :source-file ~/.tmux.conf
Quick Reference
| Task | Command / Keys |
|---|---|
| Create session | tmux new -s name |
| List sessions | tmux ls |
| Attach by name | tmux attach -t name |
| Detach | Ctrl+b d |
| Rename session | tmux rename-session -t old new |
| Kill session | tmux kill-session -t name |
| Kill all sessions | tmux kill-server |
| New window | Ctrl+b c |
| Window list | Ctrl+b w |
| Split horizontally | Ctrl+b " |
| Split vertically | Ctrl+b % |
| Apply config | Ctrl+b :source-file ~/.tmux.conf |