mosh(1)
Mobile Shell provides a responsive remote terminal connection that survives network changes and roaming.
Synopsis
mosh [OPTION]... [USER@]HOST [COMMAND]Description
Mosh is a remote terminal application that works like SSH but is designed for mobile and unstable networks. It synchronizes terminal state between client and server, allowing the connection to survive WiFi dropouts, IP address changes, and laptop sleep/wake cycles without dropping the session.
Mosh uses SSH for authentication and initial connection setup, then switches to a private UDP-based protocol (running on ports 60000-61000 by default) for the interactive session. This makes it particularly useful for working on unreliable networks or when frequently moving between networks.
Common options
| Flag | What it does |
|---|---|
-p PORT, --port=PORT | Server port for SSH connection (default 22) |
-a, --aliases | Treat hostname as alias and resolve to IP address for UDP |
-l USER, --login=USER | Specify remote username (alternative to user@ syntax) |
-ssh=COMMAND | Use specified SSH command instead of default ssh |
--predict=always|never|adaptive | Control local echo prediction (default: adaptive) |
-6, --prefer-ipv6 | Prefer IPv6 addresses when both IPv4 and IPv6 are available |
-4, --prefer-ipv4 | Prefer IPv4 addresses when both IPv4 and IPv6 are available |
--no-init | Skip server-side initialization script |
-i KEY, --ssh-ident=KEY | Specify SSH identity file for authentication |
Examples
Connect to remote host with SSH authentication, then switch to mosh protocol
mosh [email protected]Connect via SSH on port 2222, then establish mosh session
mosh -p 2222 [email protected]Connect and launch screen session on remote host
mosh example.com -- screenDisable local echo prediction for slow or high-latency networks
mosh --predict=never [email protected]Connect using a specific SSH private key
mosh -i ~/.ssh/custom_key [email protected]Explicitly request IPv6 connection when available
mosh --prefer-ipv6 [email protected]