the one use case that matters: your SSH connection dies, your work doesn't.
you SSH into a server, start something long-running, your wifi drops (or laptop sleeps) → process killed, work gone.
# 1. on the server, start a session tmux # 2. do your work as usual ./long_running_thing.sh # 3. connection dies? no problem. reconnect via SSH, then: tmux attach # your session is exactly where you left it.
leave the session running and go home:
Ctrl-b d # detach (session keeps running on the server)
Ctrl-b is the "prefix": press Ctrl-b, release, then press the next key.
| tmux | start a new session |
| tmux new -s work | start a named session called "work" |
| tmux ls | list running sessions |
| tmux attach | reattach to the last session |
| tmux attach -t work | reattach to the session named "work" |
| Ctrl-b d | detach (leave it running) |
| exit | end the session for good (type it in the shell) |
ssh user@server tmux attach || tmux new -s work # reattach if it exists, else create # ... work ... Ctrl-b d # or just close your laptop lid