Introduction / Why This Is Useful
Tmux (terminal multiplexer) is a terminal multiplexer that allows you to manage multiple sessions, windows, and panes within a single terminal. It is especially useful for server administration via SSH: you can start long-running processes, disconnect, and later return to continue work from the same point. After mastering tmux, you can significantly boost your efficiency on the Linux command line by organizing your workspace for your tasks.
Requirements / Preparation
Before you begin, ensure that:
- You have access to a Linux terminal (Ubuntu, Debian, Fedora, etc.).
- You have privileges to install packages (usually via
sudo). - You have basic command-line familiarity (navigation, executing commands).
- Tmux version 3.0 or newer (most modern distributions have the latest version).
Step-by-Step Guide
Step 1: Install tmux
Install tmux using your distribution's package manager. For most Debian/Ubuntu-based distributions:
sudo apt update
sudo apt install tmux
For Fedora/RHEL:
sudo dnf install tmux
For Arch Linux:
sudo pacman -S tmux
After installation, check the version:
tmux -V
# Example output: tmux 3.3a
Step 2: Create a New Session
Start tmux by creating a session with a descriptive name:
tmux new -s work
You will see a status line at the bottom of the screen with the session name (work), window number, and time. Now all commands inside tmux are executed with the prefix Ctrl+b (by default), followed by another key.
Step 3: Basic Window Operations
Within a session, you work with windows—similar to tabs.
- Create a new window:
Ctrl+b c - Switch between windows:
Ctrl+b n(next) orCtrl+b p(previous). You can also useCtrl+b 0..9to jump by number. - Rename the current window:
Ctrl+b ,(type a name, pressEnter). - Close a window: exit the shell (e.g.,
exit) or pressCtrl+b &(confirm withy).
Step 4: Splitting Panes
Tmux allows you to split a window into multiple panes for simultaneous viewing.
- Split vertically (left/right):
Ctrl+b % - Split horizontally (top/bottom):
Ctrl+b " - Switch between panes:
Ctrl+b arrow(in the direction of the pane). - Close a pane: exit the shell in it or press
Ctrl+b x(confirm withy).
Step 5: Detach and Reattach
One of tmux's key features is detaching without terminating processes.
- Detach from a session:
Ctrl+b d - Reattach to a session:
tmux attach -t work - Attach to a different session:
tmux attach -t other_name
You can also create a new session in another terminal and work in parallel.
Step 6: Manage Sessions from Outside
When outside tmux, it's useful to manage sessions via the CLI.
- List active sessions:
tmux ls - Rename a session:
tmux rename-session -t old_name new_name - Kill a session:
tmux kill-session -t work - Create a session and immediately run a command:
tmux new -d -s backup 'tar -czf /backup.tar.gz /important_folder'(the session will run in the background).
Verification
Ensure tmux is working correctly:
- Create a session, open several windows and panes.
- Detach (
Ctrl+b d), then open another terminal and runtmux attach -t <session_name>—you should return to the same state. - Start a long-running command (e.g.,
ping 8.8.8.8), detach, reconnect—thepingprocess should continue. - Verify that windows and panes are preserved.
Potential Issues
⚠️ Prefix Conflict with Other Software
IfCtrl+bis already used (e.g., in Vim), change the prefix. Addset -g prefix C-ato~/.tmux.conf(replaces withCtrl+a). Restart tmux.
⚠️ Cannot Copy Text with Mouse
By default, tmux captures the mouse. To copy via the system clipboard, enable mouse support: addset -g mouse onto~/.tmux.conf. Reload the config:Ctrl+b : source-file ~/.tmux.conf.
⚠️ Session Does Not Persist After Reboot
Tmux stores sessions only in memory. For auto-saving, use plugins (e.g.,tmux-resurrect). Install via a plugin manager (TPM) and add it to.tmux.conf.
⚠️ "no server running" Error on Attach
The session has already ended or was killed. Check the list:tmux ls. If no sessions exist, create a new one.