PCsuggest

  • Quick tip
  • SECURITY
  • NETWORKING
  • OpenWrt
  • HARDWARE

Mosh, a robust alternative to SSH

Updated - October 10, 2017 by Arnab Satapathi

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.

Contents

  • Where Mosh beat the SSH, telnet or rlogin ?
  • Install Mosh on Linux
  • Basic usage of Mosh
  • Firewall configuration
  • Conclusion

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.

  1. Stay connected even the internet is disconnected and reconnected again, i.e. disconnect the Wi-Fi network and witch to mobile broadband.
  2. The connection will be intact in case you put your device in sleep mode or hibernated mode, just like nothing happened.
  3. It's much more responsive in slow internet connection, seamless typing and line editing experience.
  4. No root privilege required to run both of the client and server, a big advantage in restricted environments.
  5. 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.

Install Mosh on Linux

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.

  1. In any Debian derivative like Ubuntu, Mint, install it with apt
    sudo apt-get install mosh
  2. In any Archlinux based distro, install it with pacman
    pacman -S mosh
  3. In Fedora install it with yum
    sudo yum install mosh
  4. In openSUSE, install it with zypper
    sudo zypper in mosh

To installing in any other platform, follow the official guide. It also runs on Chrome/Chromium browser as an extension, get the chrome extension here.

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.

amazon prime logo
Try AmazonPrime for free
Enjoy free shipping and One-Day delivery, cancel any time.

To connect a already running SSH server, where Mosh is also installed, use the mosh command like bellow.

mosh user@remote_host

Example, Ubuntu running on VirtualBox

mosh ubuntu@192.168.56.101

If somehow the connection is dropped, there will be message like bellow mosh ssh alternative lost connectionIf the internet is connected again and the client device could reach the server, the Mosh session will be restored again.

If the SSH server is using a different port than 22 , use mosh like bellow,

mosh --ssh="ssh -p 2222" user@host

Firewall configuration

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.

Conclusion

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.

Filed Under: how to Tagged With: mosh, shell, ssh

Your comments
  1. Quimporte says

    April 28, 2016

    If you said it must be installed on server side please explain how to install it on our OpenWRT server.

    Thx

    Reply
    • Arnab says

      April 28, 2016

      This is the thing I'm working on, as Mosh is not ported to OpenWRT yet, but in a slow pace, with almost zero coding skill, and thanks for your interest.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © PCsuggest.com · All rights reserved.

  • Home
  • About
  • Contact
  • Privacy Policy
  • Sitemap