Mosh - Mobile Shell
Updated 4/23/2026
Mosh - Mobile Shell
Mosh is SSH with roaming support - maintain persistent terminal sessions even when switching networks, dealing with intermittent connectivity, or closing your laptop.
Key advantage: Connection survives network changes, sleep/wake cycles, and temporary disconnections.
Installation
macOS:
bashbrew install mosh
Linux:
bash# Debian/Ubuntu sudo apt install mosh # Arch sudo pacman -S mosh # Fedora sudo dnf install mosh
Server-side: Must be installed on both client and server.
Basic Usage
Replace ssh with mosh:
bash# Instead of: ssh user@server # Use: mosh user@server
With SSH options:
bashmosh user@server --ssh="ssh -p 2222 -i ~/.ssh/custom_key"
Roaming Support
The magic: Switch networks without disconnection.
Scenario 1: Laptop sleep/wake
bashmosh user@server # Work on remote server # Close laptop (sleep) # Open laptop (wake, different network) # Session instantly reconnects - no "broken pipe"
Scenario 2: Wi-Fi → Cellular
bash# Connected via office Wi-Fi mosh user@server # Leave office, switch to phone hotspot # Session continues seamlessly
Scenario 3: Spotty connection
bash# On flaky coffee shop Wi-Fi mosh user@server # Connection drops momentarily # Mosh maintains session, reconnects automatically # No lost work
How It Works
Mosh uses UDP (not TCP):
- Initial connection via SSH (authentication)
- Switches to UDP for session (ports 60000-61000)
- State synchronization protocol keeps session alive
- Client/server sync state even during disconnection
Benefits:
- Survives IP address changes
- Tolerates packet loss
- Instant reconnection
- Local echo (responsive typing)
Use Cases
Remote Work (Unreliable Networks)
Coffee shop, airport, train:
bashmosh user@work-server # Connection may drop, but session persists
Long-Running Tasks
Start process, close laptop:
bashmosh user@server ./long-running-script.sh # Close laptop # Come back hours later # Session still running, script output visible
Tmux Integration
Perfect combo:
bash# On server: Start tmux tmux new -s work # From laptop: mosh user@server -- tmux attach -t work
Triple persistence:
- Tmux keeps session alive on server
- Mosh maintains connection during network changes
- Can disconnect Mosh, reconnect later, tmux session intact
Comparison: Mosh vs SSH
| Feature | SSH | Mosh |
|---|---|---|
| Roaming | No (breaks on IP change) | Yes |
| Sleep/wake | Breaks | Survives |
| Spotty Wi-Fi | Drops | Tolerates |
| Local echo | No | Yes |
| Port forwarding | Yes | No |
| Protocol | TCP | UDP (after SSH auth) |
Use SSH when: Need port forwarding, agent forwarding.
Use Mosh when: Mobile work, unreliable networks, long sessions.
Links
NetworkChuck Video: 37 INSANE Linux Commands
- URL: https://www.youtube.com/watch?v=6P-vjgPx9ww
- Summary: Demonstrates Mosh maintaining connection across network changes
- Related: Wormhole, asciinema, Lazy Docker