What is Mosh and is it better than SSH?

I’m an early Mosh user and after using it for almost a year now it’s time to shout about it to other *nix administrators and engineers cause it is a fantastic tool for anyone that spends most of the day in black terminal.

What is Mosh

Mosh (stands for Mobile Shell) is a replacement of SSH (well… almost) for remote connections to *nix systems.

How is Mosh different than SSH?

First of all, Mosh uses a new protocol called the State Synchronization Protocol (SSP) that runs over UDP (SSH uses TCP) and you may say that this is the main difference looking from user point of view. With SSP it is possible to synchronize the state of an object from one host to another. Additionally, Mosh has a “split” terminal emulator that maintains images of the screen state at both the server and client and uses SSP to synchronize them.

Well… anything else?

Lets go through what it means for everyday use:

  1. Stay connected even if your IP is changed or you have been disconnected for short or long time. Simply and automatically you getting reconnect without questions asked. Roaming feature is something that we do not have in SSH but with a help of AutoSSH and TMUX or good old Screen we kind of solved the problem. With Mosh is baked in.
  2. No root rights needed to use Mosh. Unlike SSH Mosh server is not a daemon that needs to listen on specific port to accept incoming connections from clients. Mosh server and client are executables that could be run by ordinary user.
  3. You use the same credentials for remote login as you have used before. Mosh uses SSH for authorization so in order to open connection you need the same credentials as before and that is why you still need to have ssh on your server.
  4. Use of UDP instead of TCP brings back responsiveness to sessions on a lagged links. Unlike SSH, Mosh doesn’t fill up network buffers so even if you accidentally requested to output 10GB file you will be able to hit Ctrl+C and stop it immediately. Also you don’t need to wait until server replies to see your typing. For example using Vim on slow connections is no different than editing it locally.

If you looking for some internals, have a look at presentation from Keith Winstein at last Usenix 2012:

My use case

Mosh fits into the category of tools that (at least for me) just work. As a frequent traveller, Mosh really shines when I’m on a crappy connection (like tethered through my phone or on unstable hotel wifi) or when I suspend my laptop at home and wake it up at work, the connection is instantly available. Also, no more annoying network lag! It gives instant response to typing, deleting, and line editing, typical problems with Bufferbloat, which has been increasing latencies, now are over for me. Though, I still use Tmux with it, which a bit defeats the purpose of Mosh. In my case, Tmux preserves my server state, and Mosh performs automatic reconnection when my local connection dies or my local IP changes.. but hey, now I have terminal multiplexing and smooth experience!

Even if you don’t see still the reason to move from SSH, let me put a cherry on top.

You work remotely and suddenly you network is gone. SSH will just happily freeze without any notification, meanwhile Mosh will give you nice notification on the top of your terminal with time counting from last successful connection. Nitty, right?

Now with SSH, you will have to reestablish connection from scratch (SSH can reconnect, but it takes ages), possibly also type in your password etc. With Mosh, it will reconnect immediately whenever connection is back!

Still not finished

Well, Mosh is not perfect. I look at it as work in progress. The main job (architecture) is done and implemented but there are some ruff edges that you need to be aware before you’ll start using it:

  • no IPv6 (and that hurts me deeply in this day and age and generally my everyday job at RIR)
  • no X forwarding
  • UTF-8 only (I would call it a feature as Unicode support is just perfect)
  • additional UDP ports open on firewall (as many as connecting devices)

How to get it

Mosh is available basically for any *nix systems and generally available in most distributions straight out of official repositories. If you can’t find packages for your particular system just compile it from source (the code compiles even under Cygwin with not too much effort as well). Still the place to go is Mosh website mosh.mit.edu which has plenty of useful informations about most of popular use cases like “I’m running SSH server on some weird port”.