Tmux — the lifehack that keeps your SSH session alive through internet dropouts
Working on a server over SSH and worried that an internet dropout or an accidentally closed terminal window will kill a long-running task? There's a simple and elegant fix — tmux. It's a terminal multiplexer that runs commands in a background "session" on the server, living independently of your SSH connection.
The problem
When your SSH connection drops — internet flickers, you close the window, your laptop restarts — every process started in that terminal dies. If a long task was running (an update, a backup, a long render), it's simply lost.
What tmux does
Tmux keeps your commands in a session that lives on the server independent of SSH. Connection drops → the session keeps running. You reconnect → everything is still there, as if nothing happened.
How to use it
1. Install on the server (ubuntu/debian):
sudo apt install -y tmux
2. Start a named session:
tmux new -s hermes
The -s hermes flag names the session — you reconnect to it by name. Now you're inside tmux and can run whatever you need.
3. "Detach" without closing the session:
Inside tmux press Ctrl + B, then D (detach). The session keeps running in the background, and you return to a normal terminal. Now you can safely close SSH or lose internet — your commands keep going.
4. Reconnect to the session:
tmux attach -t hermes
Everything is right where you left it — no losses.
Quick cheat sheet
| Command | What it does |
|---|---|
tmux ls |
List all sessions |
tmux new -s name |
Create a session |
tmux attach -t name |
Attach to a session |
Ctrl + B, D |
Detach |
Ctrl + B, C |
New window |
Ctrl + B, 0/1/2 |
Switch window |
Ctrl + B, :kill-session |
Kill a session |
Things to keep in mind
- A tmux session lives as long as the server does. Rebooting the server kills sessions — that's normal.
- Don't just close the window — detach first (
Ctrl+B, D), otherwise tmux may terminate the session. - Sessions accumulate — check
tmux lsperiodically and kill unneeded ones (kill-session); they eat server memory. - Don't keep sudo passwords and secrets in a tmux session — everything there is plain text.
Quick practice
tmux new -s test
# inside run: top
Ctrl + B, D # detach
# close the SSH window, reopen
tmux attach -t test # confirm top is still running
Why it matters to me
If you run hermes (or any long task) inside a tmux session on the server, it won't be interrupted by an internet dropout. That's exactly what you need when working with a remote server and constant reconnections.