Mosh: SSH alternative for unstable networks

SSH is great tool for connecting your machines remotely, but the user experience suffers from high latency of cellular networks and IP address changes caused by unstable network or changing between cellular/Wifi will drop the connection and will require manual reconnecting.

Mosh is a SSH alternative which solves these issues in pursuit of developing ideal remote shell application for mobile use. It’s available for multiple Linux/Unix distributions in their repositories, OS X with Homebrew, Android and you can compile it for Jolla phone too.

Usage examples

Installation in Fedora:

$ sudo yum install mosh

Mosh will initiate connection through SSH and it will use that connection to start actual Mosh server at the remote host, so mosh-server have to be available at the remote host. Usage is similar to command line SSH:

$ mosh username@remote-host

Using custom port for initial SSH connection:

$ mosh --ssh="ssh -p 2222" user@remote-host

Usigin specific private key for authentication:

$ mosh --ssh="ssh -i ~/.ssh/other_key" user@remote-host

How it handles roaming and network delays

Mosh command used in above examples is a wrapper script which starts mosh-server at the remote host using SSH and then connects local mosh-client to that server.

Mosh client and server communicates using UDP protocol. UDP doesn’t have persistent connection like the TCP used in SSH and that allows changes in local host’s IP during the session.

Both Mosh client and server stores the state of the displayed screen and uses local echoing to prevent network latency from interfering text input by the user. In comparison, SSH requires full round trip before it will display the given input.