Mosh, a robust alternative to SSH
Remote terminal apps like SSH, telnet, rlogin are essential to manage remote servers without VNC or web based management panel, mot sysadmin spends hours on them.
Mosh is another remote shell app, just like SSH but more robust and fail proof. The name Mosh is shortened form of “mobile shell”. This SSH alternative is intended to replace SSH and counter the existing problem of SSH.
Where Mosh beat the SSH, telnet or rlogin ?
Mosh is designed to be fail proof, disconnect and reconnect frequently without dropping the Mosh session, and much responsive on slow internet connection.
- Stay connected even the internet is disconnected and reconnected again, i.e. disconnect the Wi-Fi network and witch to mobile broadband.
- The connection will be intact in case you put your device in sleep mode or hibernated mode, just like nothing happened.
- It’s much more responsive in slow internet connection, seamless typing and line editing experience.
- No root privilege required to run both of the client and server, a big advantage in restricted environments.
- Mosh is immune to packet loss and doesn’t fill the network buffers, easier to kill a out of control process with Ctrl + C .
Know more about Mosh features at here.
Mosh is a cross platform application, runs on all UNIX like operating systems, including Windows via Cygwin. Precompiled binary packages are available for most GNU/Linux distros.
We need to install mosh both on client and server side to use it, don’t forget to install mosh on both local machine and remote machine.
- In any Debian derivative like Ubuntu, Mint, install it with apt
sudo apt-get install mosh
- In any Archlinux based distro, install it with pacman
pacman -S mosh
- In Fedora install it with yum
sudo yum install mosh
- In openSUSE, install it with zypper
sudo zypper in mosh
Basic usage of Mosh
Mosh server app needs a UTF-8 native locale to run, I’m using no locale, i.e. LANG=C , so I’ve to generate the en_US.UTF-8 locale.
sudo locale-gen en_US.UTF-8
Check it with the
locale command to be sure.
Mosh is not totally a drop in replacement for the ssh command, some commands matches where some doesn’t.
To connect a already running SSH server, where Mosh is also installed, use the mosh command like bellow.
mosh [email protected]_host
Example, Ubuntu running on VirtualBox
mosh [email protected]
If the SSH server is using a different port than 22 , use mosh like bellow,
mosh --ssh="ssh -p 2222" [email protected]
Mosh connects over UDP protocol, and uses the ports between 60000 and 61000 , so you need to open those ports in your firewall configuration.
In Ubuntu, Mosh installation package contains a ufw rule to allow connection to ports between 60000 and 61000, if you want to view this file, it’s /etc/ufw/applications.d/mosh .
If using ufw but the above ufw rule is missing use the command bellow
sudo ufw allow 60000:61000/udp
For a iptables based firewall, use this command to open ports between 60000 and 61000,
sudo iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT
You may stop the firewall application temporarily if having problems to start a Mosh session through the firewall.
No doubt Mosh is the lifesaver for low speed high latency network, but it still have to go a long way to be a real alternative to SSH, I mean independent of SSH.
It also lacks an important feature of SSH, X11 forwarding, hope this will be added in upcoming versions.
Suggestions and questions are highly welcome, this will help to improve the quality of this tutorial.
P.S– This tutorial is written as the first part of effort to run Mosh on OpenWrt devices, suggested by long-time valuable reader “miguipda”, .