How To Install and Use Mosh on Ubuntu 24.04
Welcome to the Greenhost.cloud blog! Today, we’re diving into Mosh, an incredibly useful tool for remote terminal sessions that enhances your command-line experience, especially when working over unstable connections. If you’re using Ubuntu 24.04 and are interested in improving your remote access capabilities, this guide will walk you through the installation and basic usage of Mosh.
What is Mosh?
Mosh (Mobile Shell) is a remote terminal application that allows you to connect to a server over SSH but with a few key advantages:
- Connection Resilience: Mosh maintains your session even if your connection drops. You can move between networks (like Wi-Fi to mobile data) without losing your terminal session.
- Low Latency: Mosh uses a different protocol from SSH, reducing lag and providing a more responsive experience, particularly on high-latency connections.
- Predictive Text: Mosh predicts your keystrokes, allowing for a smoother typing experience even when the connection is slow.
Prerequisites
Before we start, ensure you have the following:
- A system running Ubuntu 24.04.
- Access to the terminal.
- An SSH server installed on the remote machine you want to connect to.
Step 1: Install Mosh
Installing Mosh on Ubuntu 24.04 is straightforward. Open your terminal and run the following commands:
sudo apt update
sudo apt install mosh
This command will update your package list and install Mosh along with its necessary dependencies.
Step 2: Install Mosh on the Remote Server
To use Mosh, you’ll need to install it on any remote server you want to connect to as well. SSH into your server and run the same installation command:
sudo apt update
sudo apt install mosh
Step 3: Configure Firewall (if needed)
Mosh uses UDP ports for communication, which means you might need to configure your firewall to allow this traffic. By default, Mosh uses ports ranging from 60000 to 61000. If you are using ufw
, you can enable these ports with the following commands:
sudo ufw allow 60000:61000/udp
If you’re using a different firewall, ensure that UDP traffic is allowed on the necessary ports.
Step 4: Connecting with Mosh
Once Mosh is installed on both your local machine and the remote server, you can start a Mosh session. The basic syntax for connecting using Mosh is:
mosh user@remote-server
Replace user
with your username and remote-server
with the IP address or hostname of your server. For example:
mosh [email protected]
Mosh will establish a connection, and you’ll be greeted with a terminal session on the remote server.
Step 5: Enjoy the Benefits
Now that you’re connected, you can enjoy all the benefits Mosh offers! Here are some tips for a better experience:
- Seamless Transition: If you lose your connection, simply reconnect using the same
mosh
command, and you’ll pick up right where you left off. - Multiple Sessions: You can run multiple Mosh sessions simultaneously. Just open a new terminal window and initiate another Mosh connection.
- Customization: You can customize Mosh’s behavior with a variety of command-line options. For instance, you can specify a different port or adjust the timeout settings.
Troubleshooting
If you encounter any issues:
- Ensure that both Mosh and the SSH server are installed correctly on both machines.
- Check your firewall settings to confirm that the necessary UDP ports are open.
- Make sure you are using the correct user credentials and server address.
Conclusion
Mosh is an excellent tool for anyone who needs a reliable and responsive terminal experience over remote connections, especially when dealing with fluctuating network conditions. By following the steps outlined in this post, you can easily install and start using Mosh on your Ubuntu 24.04 system.
For more insightful tutorials and tips, stay tuned to the Greenhost.cloud blog!