Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

tmux, or how i stopped losing my work to a dropped ssh

Why a detached tmux session on the remote box turns a flaky connection from a disaster into a shrug.

A keyboard and terminal in low light

For years my relationship with long-running remote commands was one of quiet dread. You start a build, or a migration, or a tar of something enormous, the train goes into a tunnel, the SSH session drops, and the process dies with it. Or it doesn't die but you can never get back to it, which is somehow worse.

The fix is tmux, and the only command you really need to start is tmux new -s work. That gives you a named session that lives on the remote machine, not in your terminal. Hit Ctrl-b d to detach, close your laptop, walk off, and the session keeps running. Come back later, tmux attach -t work, and it's exactly as you left it, scrollback and all.

That single workflow, detach and reattach, is ninety per cent of the value. The split panes and the status bar fiddling are nice, and I've spent more evenings than I'd admit tweaking my .tmux.conf, but none of it matters next to the basic fact that the work survives the connection. The first time a train tunnel kills your SSH and you reattach to find the build merrily finished, you're converted for life. I haven't lost a long-running job to a dropped session since.