tmux and screen let a terminal session keep running even after you disconnect — essential for long-running commands, or simply avoiding losing your work if your SSH connection drops unexpectedly.
The Problem They Solve
Without a session multiplexer, closing your SSH connection (deliberately or accidentally) terminates any running foreground processes — tmux/screen keep the session alive on the server, letting you reattach later exactly where you left off.
Installing tmux
sudo apt install tmux -y
Starting a New tmux Session
tmux new -s mysession
Detaching from a Session (Without Ending It)
Ctrl+b, then d
The process(es) running inside continue running on the server even after you disconnect.
Reattaching to a Session
tmux attach -t mysession
Listing Active Sessions
tmux ls
Killing a Session
tmux kill-session -t mysession
Splitting Panes Within tmux
Ctrl+b, then % # split vertically
Ctrl+b, then " # split horizontally
Ctrl+b, then arrow keys # navigate between panes
Creating Multiple Windows Within One Session
Ctrl+b, then c # new window
Ctrl+b, then n # next window
Ctrl+b, then p # previous window
Installing screen (Alternative)
sudo apt install screen -y
Basic screen Usage
screen -S mysession # start a named session
Ctrl+a, then d # detach
screen -r mysession # reattach
screen -ls # list sessions
tmux vs screen: Which to Choose
Both accomplish the same core goal — tmux is generally considered more modern with more flexible pane/window management and better default configurability; screen is older but still perfectly functional and pre-installed on some systems. Either is a reasonable choice; consistency (picking one and learning it well) matters more than which specific tool.
Practical Use Case: Running a Long Installation
tmux new -s install
./long-running-install.sh
# Ctrl+b, d to detach and check back later
tmux attach -t install
Practical Use Case: Monitoring Logs While Working Elsewhere
tmux new -s logs
tail -f /var/log/app.log
# Ctrl+b, d, then create another session/window for actual work
Common Errors
"session not found" when trying to reattach — verify the exact session name with tmux ls; a typo in the session name is the most common cause.
Session ended unexpectedly — if the server itself rebooted, tmux/screen sessions don't survive a reboot; only SSH disconnections, not server restarts.
Continue Reading
- How to Manage Services with systemd and systemctl
- SSH Hardening: Change the Port, Disable Root Login & Use SSH Keys
- How to Manage Multiple SSH Sessions and Config Profiles
Browse more articles in Linux Server Administration.