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.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

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

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.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.