How to install Mosh in Ubuntu?


Gaming Laptop Series

Mosh or Mobile Shell is a command-line tool to connect a client computer to a server over the internet. It is similar to SSH that has some additional features. This application is developed by Keith Winstein for Unix-like operating systems and can be used as an alternative to SSH.

In this article, I will discuss how to install and use Mosh shell on a Ubuntu system.

The key features of Mosh

Some features of Mosh are given below.

  • It maintains the session even when you are roaming
  • Uses UDP so it can maintain session even when you lose internet connection
  • The Connection remains intact when you resume the session after a long time
  • Responsive to keyboard events like typing deleting text without network lag
  • It uses the same method to login as we use in SSH
  • It has a mechanism to handle packet loss

Installing Mosh in Ubuntu

You can install Mosh from the Ubuntu repository. To install it on your Ubuntu system first update the local package repository by using –

sudo apt update

Next, use the following command to install it –

sudo apt install mosh

Press y if it asks you for confirmation.

install mosh

Verify Mosh installation

You can verify the Mosh installation by using the given command.

mosh --version

This will display the version of mosh installed on your system.

mosh version

Adjust the firewall

As discussed earlier mosh uses UDP and by default from port 6000 to 61000. So if you have a firewall enabled on the remote system then you must have to allow UDP ports for Mosh.

Use the given command to update the firewall rules on the remote system.

sudo ufw allow 60000:61000/udp

Connect remote system through Mosh

Most of you will be familiar with SSH and working with it. To use mosh both i.e. client and server should have Mosh installed and a firewall rule that allows UDP traffic on ports 60000-61000 at the remote server.

mosh username@ip_or_hostname

For example –

mosh lalit@192.168.122.17

Now if it asks you like ‘Are you sure you want to continue connecting(yes/no):’ type yes and then enter to get connected to the remote system.

What if we need to specify the ssh port other than the default port i.e. 22 or to use ssh specific options. You just need to command like it is given below.

For example, I need to connect to ssh running at port 240 on the remote server. It can be done as follows.

mosh lalit@192.168.122.17 --ssh="ssh -p 240"

Now it will be connected to the remote system.

For more help on Mosh, you can use  –

mosh --help

Conclusion

I hope now you understand how to install and use Mosh in Ubuntu. Now if you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.