Table of Contents#
- Prerequisites
- Installation on Different Linux Distributions
- Ubuntu/Debian
- CentOS/RHEL
- Arch Linux
- Configuration (Optional)
- Using Mosh
- Troubleshooting Common Issues
- Conclusion
- 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
sudoaccess) to install software on the system.
2. Installation on Different Linux Distributions#
Ubuntu/Debian#
- Update the package list:
sudo apt update- Install Mosh:
sudo apt install moshThis will download and install the Mosh package along with its dependencies.
CentOS/RHEL#
- First, enable the EPEL (Extra Packages for Enterprise Linux) repository. For CentOS 7:
sudo yum install epel-releaseFor CentOS 8 (which uses dnf instead of yum):
sudo dnf install epel-release- Then install Mosh: For CentOS 7 (using yum):
sudo yum install moshFor CentOS 8 (using dnf):
sudo dnf install moshArch Linux#
On Arch Linux, you can simply use the pacman package manager:
sudo pacman -S mosh3. 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@host4. Using Mosh#
Once installed, using Mosh is similar to SSH. The basic syntax is:
mosh [user@]hostnameFor 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.