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

tmux, and Never Losing a Session Again

Why a single long-lived tmux session per host has quietly saved me from more dropped SSH connections than I can count.

A keyboard in front of a terminal

The case for tmux is embarrassingly simple, and yet I meet engineers every year who are still losing a half-finished migration because their laptop went to sleep on the train. Your SSH session is mortal. The work on the other end shouldn't be.

My habit is one named session per host, attached on login. The login shell does the boring thing for me:

# in .bashrc on the server
if -z "$TMUX" && -n "$SSH_CONNECTION"; then
  tmux new-session -A -s main
fi

new-session -A attaches if main already exists and creates it if it doesn't, so every time I land on the box I'm back exactly where I left off. Connection drops, train goes into a tunnel, laptop lid closes: the long-running thing carries on, and I reattach when the world reconnects me.

The rest is just comfort. A couple of windows, panes when I want a log tailing next to a shell, and prefix d to detach cleanly when I'm done. I don't use the fancy plugin ecosystem and I don't need to. The one feature that earns its keep is persistence, and that's free.

If you take one thing from this: stop running long jobs in a bare SSH shell. The first time tmux hands you back an intact session after a dropout, you'll wonder why you waited.