Mosh: An ssh that does not disconnect

ssh is the defacto standard to access a remote server. It does not offer much of a point and click GUI but get things done with a fair level of security.

ssh shows however a major drawback: it is based on TCP.

title"Diagram of a TCP connection

You will likely never notice any issue until you connect to a server over ssh from a train, a plane or from a mobile device, and briefly lose your connection, or if your device switches network such as going from the Wifi to your Cellphone connection and switching back to Wifi.

In those cases, ssh will drop and won’t even tell you it dropped.

Usually, lacking feedback from your console, you will issue a CTRL+C and notice that nothing happens…​ Game Over!

1. Mosh

Mosh, the Mobile Shell aims at solving that issue.

You can watch a rather entertaining vide about Mosh here:

The requirements for Mosh are pretty light:

  • install mosh on your local machine (brew install mosh on a Mac)

  • install the mosh utility on the server (sudo apt install mosh on Linux)

  • make sure you open the UDP ports 60000-61000 on your server.

You may open less ports if you wish but keep in mind that you will need as many ports as you wish to have simultaneous connections.

You can find about the many ways to install Mosh here.

Instead of using ssh to connect to remote as user with ssh user@remote you simply use mosh user@remote.

2. Benefits

The benefits will show instantly: if you ever lose your connection of switch network, Mosh will instantly show it to you but most important, it will recover automagically.

On very slow connection, you may enjoy a better feedback thanks to Mosh Predictive Local Echo. In practise, I found it better than ssh for sure but not as amazing as shown in the video.

3. Drawbacks

Mosh is not a perfect solution…​ First you will notice that mosh does not allow scrolling. Say you enter a command with a verbose output such as pd -edf. While ssh lets you scroll back and forth, mosh will NOT allow that, at least not without additioanl tricks.

I also found Mosh having a few minor issues with not rendering some chars or rendering them improperly. I have seen letters rendered as others so I would not rely on Mosh when having to view critical information.

4. Conclusion

During my first test, I enthusiastically switched to Mosh during a trip in a train. The improvement was immediate but I noticed the aforementioned glitches pretty quickly. I then switched back to ssh thinking it was not that bad just to realize actually how much mosh improved my experience and allowed me to keep working without having to get angry at my jumpy train Wifi.

Overall, the worst your connection is and the more I would recommend using mosh. I would however, not be considering mosh as a complete replacement for ssh if you work on critical tasks or enjoy fair connectivity.

This site is best viewed using the Brave browser.

Not only it will help you block most trackers, keep you safer on the internet but it also allows you supporting websites such as this one without having to spend a dime.

Using Brave allows me bringing this content to you, without any ad, subscription and other annoyance (I am looking at you Medium…​). Using Brave gives you the opportunity to show your appreciation for that in a few clicks!

You can read more about Brave in this article.

Wilfried Kopp aka. Chevdor
Building Blockchains & Decentralized Solutions

I build decentralized solutions and tooling to support them. I am developing Smart Contracts and dApps on Ethereum and developing tooling for Substrate (Polkadot & Kusama). I love Rust! I am using Docker extensively and above all I like efficiency. GPG Fingerprint 15AF C574 D3F9 F1C3 CCDD E31E 2DCE C4DC 506E 6475.