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, long history, vi keys
set -g mouse on
set -g history-limit 50000
setw -g mode-keys vi
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'
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.
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. Reboot the server, reconnect, and your windows come back.
- 17 Oct 2026First written.