dotlinux blog

How to Install Mosh Shell as SSH Alternative on Linux

In the world of Linux systems, SSH (Secure Shell) has long been the go-to tool for remote access. However, it has some limitations, especially in environments with unstable network connections. Mosh (Mobile Shell) comes to the rescue. Mosh offers advantages like better handling of intermittent connectivity, faster response times, and support for roaming between different networks. In this blog, we'll guide you through the process of installing Mosh on Linux.

2026-04

Table of Contents#

  1. Prerequisites
  2. Installation on Different Linux Distributions
    • Ubuntu/Debian
    • CentOS/RHEL
    • Arch Linux
  3. Configuration (Optional)
  4. Using Mosh
  5. Troubleshooting Common Issues
  6. Conclusion
  7. References

1. Prerequisites#

Before installing Mosh, make sure your Linux system meets the following requirements:

  • A working internet connection to download the necessary packages.
  • Sufficient permissions (usually sudo access) to install software on the system.

2. Installation on Different Linux Distributions#

Ubuntu/Debian#

  1. Update the package list:
sudo apt update
  1. Install Mosh:
sudo apt install mosh

This will download and install the Mosh package along with its dependencies.

CentOS/RHEL#

  1. First, enable the EPEL (Extra Packages for Enterprise Linux) repository. For CentOS 7:
sudo yum install epel-release

For CentOS 8 (which uses dnf instead of yum):

sudo dnf install epel-release
  1. Then install Mosh: For CentOS 7 (using yum):
sudo yum install mosh

For CentOS 8 (using dnf):

sudo dnf install mosh

Arch Linux#

On Arch Linux, you can simply use the pacman package manager:

sudo pacman -S mosh

3. Configuration (Optional)#

Mosh can be configured through environment variables or command-line options if you need to customize its behavior.

  • Port Range: Mosh uses a range of UDP ports by default. You can change this range by setting environment variables. For example:
export MOSH_SERVER_UDP_PORT_MIN=60000
export MOSH_SERVER_UDP_PORT_MAX=61000
  • Compression: You can enable or disable compression. By default, it's enabled. To disable, set:
export MOSH_COMPRESSION=0
  • Custom SSH Port: If your SSH server runs on a non-default port, you can specify it using:
mosh --ssh="ssh -p 2222" user@host

4. Using Mosh#

Once installed, using Mosh is similar to SSH. The basic syntax is:

mosh [user@]hostname

For example, if you want to connect to a server with the IP 192.168.1.100 as the user john:

mosh [email protected]

Mosh will automatically handle the connection, and if the network connection drops and then comes back (like when you move between Wi-Fi networks), it will resume the session without you having to reconnect from scratch.

5. Troubleshooting Common Issues#

  • Firewall Blocking: If you can't connect, check your firewall settings. Make sure the UDP port range (as configured in Mosh or the default one) is allowed through. For example, on Ubuntu with ufw (Uncomplicated Firewall), you can allow a port range like this:
sudo ufw allow 60000:61000/udp
  • Missing Dependencies: If the installation fails, double-check that you have enabled the correct repositories (especially for CentOS/RHEL with EPEL). Try reinstalling the dependencies first.

6. Conclusion#

Mosh is a great alternative to SSH, especially in scenarios where network connectivity is not always stable. By following the steps in this blog, you should be able to install Mosh on your Linux system and start enjoying its benefits.

7. References#