$linuxjunkies
>

mosh(1)

Mobile Shell provides a responsive remote terminal connection that survives network changes and roaming.

UbuntuDebianFedoraArch

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

FlagWhat it does
-p PORT, --port=PORTServer port for SSH connection (default 22)
-a, --aliasesTreat hostname as alias and resolve to IP address for UDP
-l USER, --login=USERSpecify remote username (alternative to user@ syntax)
-ssh=COMMANDUse specified SSH command instead of default ssh
--predict=always|never|adaptiveControl local echo prediction (default: adaptive)
-6, --prefer-ipv6Prefer IPv6 addresses when both IPv4 and IPv6 are available
-4, --prefer-ipv4Prefer IPv4 addresses when both IPv4 and IPv6 are available
--no-initSkip server-side initialization script
-i KEY, --ssh-ident=KEYSpecify 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 -- screen

Disable 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]

Related commands