tmux is a terminal multiplexer: it lets you run multiple terminal sessions, windows, and panes inside one terminal. Its standout feature is that work can keep running on a remote machine after you disconnect—and you can reattach later.
On Ubuntu or another Debian-based system:
sudo apt install tmux
Start tmux:
tmux
You can use it locally or SSH into a Linux server first and run it there.
Start a long-running task inside tmux, such as a ping:
ping example.com
Detach without stopping the task:
Reattach to the most recent session:
tmux attach
Or use the shortcut:
tmux a
This is useful when your SSH connection drops or you want to resume work from another device.
List existing sessions:
tmux ls
Create a named session:
tmux new -s Bob
Attach to a specific session:
tmux attach -t Bob
Kill a specific session:
tmux kill-session -t Bob
To stop the tmux server and all its sessions:
tmux kill-server
The default tmux prefix key is Ctrl+B. Press it first, release it, then press the next key.
| Action | Keys |
|---|---|
| Split into side-by-side panes | Ctrl+B, then % |
| Split into stacked panes | Ctrl+B, then " |
| Move between panes | Ctrl+B, then an arrow key |
| Show pane numbers | Ctrl+B, then Q; press a number to select a pane |
| Resize the active pane | Ctrl+B, then Ctrl+arrow |
| Choose a preset pane layout | Ctrl+B, then Alt+1 through Alt+5 |
| Close the active pane | Ctrl+B, then X, then confirm |
| Action | Keys |
|---|---|
| Create a window | Ctrl+B, then C |
| Move to the next window | Ctrl+B, then N |
| Rename the current window | Ctrl+B, then , |
| Browse windows and sessions | Ctrl+B, then W |
| Close the current window | Ctrl+B, then &, then confirm |
Create or edit ~/.tmux.conf to enable mouse support and Vim-style navigation in copy mode:
set -g mouse on
setw -g mode-keys vi
To copy text using the keyboard:
[ to enter copy mode.] to paste.You don’t need to learn every feature at once. Even using tmux just to start a task, detach, and reattach later can make remote Linux work much more reliable.