For those who love to work remotely, must know about SSH. This protocol is widely used by system administrators. SSH is also available in all platforms like Linux, Unix, Microsoft Windows, and Macintosh. But today, we have Mosh as an alternative for SSH.
What is Mosh
Mosh is a remote-terminal protocol like SSH. As it’s name, Mobile Shell (Mosh) is optimized for mobile working. It allows roaming, support intermittent connectivity and provides intelligent local echo and line editing of user keystrokes.
From its website, here’s some features that Mosh supports :
- Roaming support
- Support intermittent connectivity
- Provides intelligent local echo
- Same login method
- No daemon
- Instant response to typing, deleting and line editing
- Control-C works great
Mosh need to be installed on both the client and the server. Luckily, Mosh is available in Linux, Windows (using Cygwin), BSD, Solaris, Android and the latest one is Chrome OS. Here are some installation examples in Ubuntu and CentOS Linux :
On Ubuntu Linux :
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa.keithw/mosh
$ sudo apt-get update
$ sudo apt-get install mosh
On CentOS / Fedora :
# yum install mosh
How to use Mosh
To run mosh, the easiest way to do that is by typing
$ mosh remote_destination
Mosh will try to connect ot remote_destination using current user. If we want to define the user, then we can type :
$ mosh [email protected]_server
First, Mosh will log the user in via SSH. Once you connect it, Mosh will start UDP connection between port 60000 and 61000. To check it, we can use nc command.
Since Mosh using UDP to connect, Mosh is robust to roaming.
Here is an example. You remote another server using SSH. Then you have a network glitch or your network connection is changed from wired to wireless connection. In this situation your SSH connection may disconnect. Suddenly you can’t type anything on your SSH console. But SSH did not tell you that the connection is already disconnect.
Mosh, will tell you if Mosh is losing a network connection. A notification will appear on the top of Mosh console.
User can still typing on the Mosh console. Once the network connection restored it will be synced to the server. So we don't have to close Mosh window, open Mosh again and re-connect Mosh manually
When typing is so hard because you are having bad connection, Mosh can predict your typing. Mosh will underline the predictions of your typing and removes the underlines when it confirmed by the server.
By default, local echo prediction is enabled. If you don’t want to use this feature, you can disable it. Just use --predict=never parameter, or for short just add -n parameter.
Selecting Mosh UDP port
If you are behind a port-forwader or NAT, you can manually select the UDP port for Mosh. To do this, we can use -p option followed by the port number. Let say we want to connect to port 1234, then the command will be like this.
$ mosh -p 1234 [email protected]
To test it, again we can use nc command.
Exit from Mosh or Suspend it
You can quit from Mosh by typing exit on the console. But we can also press Ctrl - ^ + . (Ctrl + number 6 + dot sign) to quit from Mosh.
Another interesting thing from Mosh is that you can suspend mosh or we can say : Minimized it. This feature is useful when you are working on the remote computer using SSH, you must exit your remote connection or open a new console to switch to your local computer if you want to work on your local computer. To avoid that, you can suspend Mosh by pressing Ctrl-^ + Ctrl-Z
Once you want to switch back to your remote computer and restore your remote screen, just type fg on your local console.
Mosh is a great alternative for SSH. It has some value added compared to SSH, such as intermittent connectivity, roaming capability, predictive text, UDP connections and ability to suspend it. Mosh also works on Linux, Unix, MacOS and Microsoft Windows platform. Please visit Mosh website to gain more detail information.