Exploring an alternative to SSH – utilizing Mosh (mobile shell)

While starting out with SSH, you might notice one quirk right away: if your network connection drops, it can be difficult to regain control of what you were doing on the machine you were connected to. This is especially common with laptops, as your connection state on such a device will change depending on where you are or what network you're connected to. While running commands within a terminal multiplexer such as tmux or screen, can keep your workflow alive even after disconnecting, there is an alternative to SSH that may work for you. Mosh (mobile shell) is an alternative to SSH that will keep your remote session alive, even if you disconnect from the network where the resource resides. When you reconnect to the network, Mosh will allow you to pick up where you left off.

Installing Mosh in Debian is extremely easy. Simply install the mosh package, as it is available from within the default repositories:

# apt-get install mosh

In CentOS, Mosh is not available from that distribution's default repositories, so you'll first need to add an additional repository in order to make it available. First, enable the EPEL repository with the following command:

# yum install epel-release

Then, you should be able to install the mosh package:

# yum install mosh

In order for Mosh to be effective, you will need to install it not only on your local machine, but also any machines you wish to connect to. The syntax is similar to SSH:

Like SSH, we can supply the -p flag to specify a different port to use:

mosh -p 2222 [email protected]

In fact, Mosh actually utilizes SSH to initiate the connection, and then the mosh program takes over from there. After you connect, you can simulate a disconnect by removing your network cable or disconnecting from your wireless access point. You will notice that the next time you connect using mosh, your session should be just as you left it. To see the magic in all its glory, consider starting a process (such as running the top command) before disconnecting.

While there are many ways to keep processes running on a remote server even when your session is disconnected, Mosh is one of the newer and more unique solutions. Give it a try!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset