mosh — Roaming-Tolerant Remote Shell over UDP

Practical guide to mosh — a latency-tolerant SSH alternative for unreliable connections, network changes, and mobile work with UDP-based roaming.

mosh is a latency-tolerant alternative to SSH for unreliable connections: the session stays alive when you switch networks, close your laptop lid, or roam across Wi-Fi access points. After an initial SSH handshake, mosh switches to UDP – making network changes and brief interruptions fully transparent. Local echo means your terminal responds instantly even on high-latency links. That makes mosh the go-to choice for remote work over mobile data, train Wi-Fi, or flaky VPNs.

Basic Usage

mosh <user>@<host> — Connect to a remote host (like ssh).

mosh admin@server.example.com

mosh <host> — Connect using current username.

mosh server.example.com

mosh --ssh='ssh -p <port>' <user>@<host> — Use a custom SSH port for the initial connection.

mosh --ssh='ssh -p 2222' admin@server.example.com

mosh --ssh='ssh -i <key>' <user>@<host> — Use a specific SSH identity key.

mosh --ssh='ssh -i ~/.ssh/id_ed25519' admin@server

Port & Network

mosh -p <port> <user>@<host> — Use a specific UDP port for mosh traffic.

mosh -p 60001 admin@server

mosh -p <start>:<end> <user>@<host> — Specify a UDP port range.

mosh -p 60000:60010 admin@server

mosh --bind-server=<addr> <user>@<host> — Bind mosh-server to a specific IP address.

mosh --bind-server=0.0.0.0 admin@server

Server Options

mosh --server=<path> <user>@<host> — Specify the path to mosh-server on the remote host.

mosh --server=/usr/local/bin/mosh-server admin@server

mosh --server='mosh-server new -l LANG=en_US.UTF-8' <host> — Set locale on the remote mosh-server.

mosh --server='mosh-server new -l LANG=en_US.UTF-8' admin@server

mosh --predict=<mode> <user>@<host> — Set prediction mode (adaptive, always, never, experimental).

mosh --predict=always admin@server

Session Management

Ctrl+^ . — Disconnect from mosh session (like ssh ~.).

Press Ctrl+^ then .

mosh <host> -- tmux a — Connect and reattach to a tmux session.

mosh admin@server -- tmux a

mosh <host> -- screen -r — Connect and reattach to a screen session.

mosh admin@server -- screen -r

Mosh vs SSH

mosh <host> — Survives network changes, sleep/wake, and Wi-Fi roaming.

mosh admin@server (keeps working after laptop sleep)

mosh <host> — Uses UDP after initial SSH handshake (more resilient under packet loss).

mosh admin@server (uses UDP port 60000+ after SSH auth)

mosh <host> — Local echo: shows keystrokes instantly even on slow connections.

mosh admin@server (responsive even on 500ms latency)

ssh <host> — Use SSH when you need port forwarding, X11, or SOCKS proxy (mosh doesn't support these).

ssh -L 8080:localhost:80 admin@server (port forwarding needs ssh)

Conclusion

mosh does not replace SSH entirely, but for mobile work and unreliable connections it is the superior choice. Pair it with tmux or screen to resume sessions seamlessly even after genuine disconnects. If you regularly work on trains, in cafés, or over mobile data, mosh deserves a permanent place in your workflow.

Further Reading

  • ssh – secure remote shell with encryption and port forwarding
  • scp – securely copy files over SSH to remote hosts
  • ssh-keygen – create and manage SSH key pairs