For years I treated a dropped SSH connection as a small tragedy. Train goes into a tunnel, laptop sleeps, VPN hiccups, and whatever I had running in the foreground dies with the shell. The fix is old and boring and I should have committed to it a decade ago: run everything inside tmux, attach and detach at will, and stop caring whether the connection survives.
The core idea is that tmux keeps your processes attached to a server that lives on the remote box, not to your terminal. Your terminal is just a window onto it. Close the window, the work keeps going. Open a new one, attach, and you are exactly where you left off.
The three commands that matter
You can be productive with almost nothing memorised:
tmux new -s work # start a named session
tmux ls # list sessions
tmux attach -t work # reattach after a dropped connection
The prefix is Ctrl-b by default. prefix d detaches, prefix c makes a new window, prefix " and prefix % split panes. That genuinely is enough to never lose a long build or a tail -f again.
The bits I changed
The default prefix fights with Emacs and readline, so I moved it. I also turned on mouse mode, because scrolling with the mouse occasionally is not a moral failing whatever the greybeards say. Here is the whole of my ~/.tmux.conf, which has barely changed in years:
# saner prefix
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# mouse on, sensible numbering
set -g mouse on
set -g base-index 1
setw -g pane-base-index 1
# more scrollback
set -g history-limit 50000
# reload config without leaving
bind r source-file ~/.tmux.conf \; display "reloaded"
# splits that keep the current path
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
The pane_current_path lines are the small luxury I would not give up. New splits open in the directory you were already in, rather than dumping you back in $HOME to cd your way back.
Why it stuck
What finally made it a habit was not the recovery from disconnects, useful as that is. It was leaving a named session running on a server for a week, attaching from three different machines over those days, and finding my mental context intact each time: same windows, same scrollback, same half-typed command. The session became the durable thing and the terminal became disposable.
If you do remote work of any kind and you are not already living in tmux or screen, spend the twenty minutes. The payoff is that a dropped connection stops being an event worth noticing.