Mosh (mobile shell) instead of ssh – really great for linux-administration

If you administrate your Linux system, you usually sit at one place and take it easy. But some tasks take longer and I sometimes stray from the terminal window. In between I also switch on a VPN or take my notebook somewhere else and it dials into another WLAN. Mobile devices are also suitable for various administrative tasks. That's why I always use screen, because it allows me to keep the session going even if I lose the connection to the server. Another option that I have grown fond of is called mosh.

The administration via ssh and screen has the advantage that it works with every SSH client. That would be for example also putty under Windows or JuiceSSH under Android.

With mosh, however, both the client and the server must be running mosh or have support for it.

What makes mosh so special?

Mosh stands for Mobile Shell and this is already a hint that the software can roam. Even if you change the network or the IP address, the connection to the server seems to remain intact, or the software re-establishes it immediately. If you use a WLAN connection on the train or have to deal with some wireless holes, that's nice.

mosh is also nice for slow connections. SSH always waits for a response from the server before you see anything in the terminal. With the mobile shell you see the typing, deleting and so on immediately. You see typos immediately and can easily correct them. The lag with SSH and slow connections can drive you mad.

In summary: mosh is great for high latency and when roaming is involved!

How does mosh authenticate?

The good news is that the mobile shell authentication runs via SSH. Once you have exchanged keys so that you can log in to the remote server without a password, you don't need to do anything else.

It's very convenient because you really only have to change the command for logging in (in the terminal).

So it works like SSH?

In principle you do. If you know how to use SSH, you will have no problems with the mobile shell. There is a dedicated page describing how to use it.

The simplest option, which also works for me is:

You may also specify UDP port or the SSH port, should that be necessary. As usual on Linux there is also a so called man page or the parameter -h shows help.

Mosh or mobile shell can roam and helps with high latency

On which operating systems does mosh run?

Officially mosh runs on almost all operating systems except Windows. The website says that the mobile shell works with GNU/Linux, BSD, macOS, Solaris, Android, Chrome and iOS. The software is free. The already mentioned JuiceSSH for example offers official support for mosh or Termux would be an alternative on Android. There is also a plugin for Chrome, so you can use it on Windows as well. With Cygwin it works supposedly also.

Under Linux Mint or Ubuntu, things are simple:

sudo apt install mosh

In the other known Linux distributions the package can also be found in the repositories. More information can be found on the project page.

Mosh can also be run as a user. Theoretically you don't need admin or root rights to install the program. But it is more comfortable to use the package manager, because there are updates available, should any be necessary.

Are there any disadvantages?

It's just a pure shell and that's great for administration via command line. As far as I understand it, X Forwarding does not work with it. This is not so dramatic on a Linux server, because X has no place there anyway. With a Raspberry Pi sitting in the distance and running Raspbian, you might miss it. Admittedly also a rather rare situation, but it is possible.

There are some really cool tools that are based on SSH. I have my fun with sshuttle or Ki4a too, I must admit. VPN purely over SSH – has overhead, sure, but works extremely well.