mosh and tmux
A connection that survives wifi changes and laptop sleep, and a shell that survives the connection.
Names and addresses are placeholders. The list says what each one stands for.
What it does here
Three layers, each covering a different failure. Tailscale finds the box on any network, mosh keeps the connection alive across network changes and sleep, and tmux keeps the shell on the server so nothing is lost if the link dies, and you can reattach from another machine.
Canonical setup
mosh has to be installed on both ends. tmux plugins come from tpm, the tmux plugin manager.
sudo apt install -y tmux mosh
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpmbrew install mosh # macOS
sudo apt install -y mosh # Debian, UbuntuUpstream: mosh, tpm, tmux-continuum.
In this build
- Sessions survive a server reboottmux-resurrect saves them and tmux-continuum restores them when the tmux server starts.
- One clean host entryThe MagicDNS name and your user, and nothing else.
- A one-word connect
devopens mosh and attaches to themainsession, creating it if needed. - Mouse on, a Ctrl-a prefix, longer historyCtrl-a instead of Ctrl-b, and 10,000 lines of scrollback.
set -g mouse on
set -g history-limit 10000
unbind C-b
set -g prefix C-a
bind C-a send-prefix
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
# Keep this line at the very bottom
run '~/.tmux/plugins/tpm/tpm'Start tmux with tmux new -A -s main and press prefix then capital I to fetch the plugins.
Host devbox
HostName devbox.example.ts.net
User youruseralias dev='mosh devbox -- tmux new -A -s main'Seams
Where this meets the rest of the build. Each one leads with what you will actually see.
Symptommosh can't start mosh-server
mosh launches its server over ssh, and a RemoteCommand in the host entry takes over that launch. Keep the host entry clean and put the tmux command in the alias.
Symptomyour windows don't come back after a reboot
Cloning the plugins into ~/.tmux/plugins isn't enough. Without the @plugin lines and the run line at the bottom of ~/.tmux.conf, tmux never loads them, so nothing is saved and nothing restores. Check with tmux show -g @continuum-restore, which should print on.
Symptomwindows come back after a reboot, but they're old ones
tmux-continuum saves every 15 minutes, and it restores the last save, not the session you were in. Reboot soon after opening windows and they're gone, or an older layout comes back. Save by hand first with prefix then Ctrl-s. ls -l ~/.local/share/tmux/resurrect/last shows when the last save happened. Restore runs when the tmux server starts, which is the first dev after boot; set -g @continuum-boot 'on' starts tmux at boot instead.
Symptommosh can't connect from a hotel or office network
mosh needs UDP 60000 to 61000. Where that's blocked, fall back to plain ssh: ssh -t devbox tmux new -A -s main, or Eternal Terminal for a TCP connection that also survives changes.
Symptomthe terminal won't scroll back
mosh keeps no scrollback of its own. Use tmux copy mode: prefix then [.
Symptomkeys go to the wrong tmux
With tmux on your own machine too, reach the inner session with the prefix pressed twice. Or run tmux only on the server.
Verify
dev # lands in the main sessionThen change networks (wifi to a phone hotspot) and the session carries on. Save with prefix then Ctrl-s, reboot the server, run dev again, and your windows come back.
- 17 Oct 2026First written.
- 23 Oct 2026Matched to the box: a Ctrl-a prefix, 10,000 lines of history, no vi keys. Added the seam for plugins that are installed but never loaded.
- 23 Oct 2026Added the seam for the 15-minute save interval, found in the reboot test. Verify now saves by hand before rebooting.