How to Install Mosh Shell as SSH Alternative on Linux

Mosh, which stands for Mobile Shell is a command-line application which is used for connecting to the server from a client computer, over the Internet. It can be used as SSH and contains more feature than Secure Shell.

It is an application similar to SSH, but with additional features. The application is written originally by Keith Winstein for Unix like operating system and released under GNU GPL v3.

Mosh Shell SSH Client
Mosh Shell SSH Client

Features of Mosh

  1. It is a remote terminal application that supports roaming.
  2. Available for all major UNIX-like OS viz., Linux, FreeBSD, Solaris, Mac OS X and Android.
  3. Intermittent Connectivity supported.
  4. Provides intelligent local echo.
  5. Line editing of user keystrokes supported.
  6. Responsive design and Robust Nature over wifi, cellular and long-distance links.
  7. Remain Connected even when IP changes. It usages UDP in place of TCP (used by SSH). TCP time out when connect is reset or new IP assigned but UDP keeps the connection open.
  8. The Connection remains intact when you resume the session after a long time.
  9. No network lag. Shows users typed key and deletions immediately without network lag.
  10. Same old method to login as it was in SSH.
  11. Mechanism to handle packet loss.

Installation of Mosh Shell in Linux

On Debian, Ubuntu and Mint alike systems, you can easily install the Mosh package with the help of apt-get package manager as shown.

# apt-get update 
# apt-get install mosh

On RHEL/CentOS/Fedora based distributions, you need to turn on third party repository called EPEL, in order to install mosh from this repository using yum package manager as shown.

# yum update
# yum install mosh

On Fedora 22+ version, you need to use dnf package manager to install mosh as shown.

# dnf install mosh

On other Linux distributions can install it as shown.

# pacman -S mosh         [On Arch/Manjaro Linux]
$ sudo zypper in mosh    [On OpenSuse]
# emerge net-misc/mosh   [On Gentoo]

How do I use Mosh Shell?

1. Let’s try to login into remote Linux server using mosh shell.

$ mosh [email protected]
Mosh Shell Remote Connection
Mosh Shell Remote Connection

Note: Did you see I got an error in connecting since the port was not open in my remote CentOS 7 box. A quick but not recommended solution I performed was:

# systemctl stop firewalld    [on Remote Server]

The preferred way is to open a port and update firewall rules. And then connect to mosh on a predefined port. For in-depth details on firewalld you may like to visit this post.

  1. How to Configure Firewalld in CentOS, RHEL and Fedora

2. Let’s assume that the default SSH port 22 was changed to port 70, in this case you can define custom port with the help of ‘-p‘ switch with mosh.

$ mosh [email protected] --ssh="ssh -p 70"

3. Check the version of installed Mosh.

$ mosh --version
Check Mosh Version
Check Mosh Version

4. You can close mosh session type ‘exit‘ on the prompt.

$ exit

5. Mosh supports a lot of options, which you may see as:

$ mosh --help
Mosh Shell Options
Mosh Shell Options

Cons of Mosh Shell

  1. Mosh requires additional prerequisite for example, allow direct connection via UDP, which was not required by SSH.
  2. Dynamic port allocation in the range of 60000-61000. The first open fort is allocated. It requires one port per connection.
  3. Default port allocation is a serious security concern, especially in production.
  4. IPv6 connections supported, but roaming on IPv6 not supported.
  5. Scrollback not supported.
  6. No X11 forwarding supported.
  7. No support for ssh-agent forwarding.

Conclusion

Mosh is a nice small utility which is available for download in the repository of most of the Linux Distributions. Though it has a few discrepancies specially security concern and additional requirement it’s features like remaining connected even while roaming is its plus point. My recommendation is Every Linux-er who deals with SSH should try this application and mind it, Mosh is worth a try.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 Comments

Leave a Reply
  1. The -p (port) option does not set the port SSH uses, although the article seems to reference an older version of MOSH. The "-p" is an option the client will use to attempt to have the server use for the UDP stream.

    To set the port SSH will use, for the SSH authentication, we need --ssh="ssh -p 70".

    ex.

    # mosh [email protected] -p=60001 --ssh="ssh -p 70"
    
    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.