1.5 C
New York
Friday, February 3, 2023

Buy now

Get persistent SSH connections with the help of Mosh

Jack Wallen shows you how to keep an SSH connection alive so you can work undisturbed.

Secure ssh on linux servers.
Image: pixeltrap/Adobe Stock

How many times have you done critical administration, only to break your Secure Shell connection? It happens for all kinds of reasons and when it happens bad things can happen. I experienced it in the middle of a kernel compilation and had no idea where the process was when I finally reconnected. While that situation has resolved itself, there are plenty of instances where it might not.

SEE: 40+ Open Source and Linux Terms You Need to Know (TechRepublic Premium)

Therefore, having a sustained SSH connection can be absolutely crucial. With a tool like Mosh (Mobile Shell) you get roaming and intermittent connectivity, intelligent echo and rule editing of keystrokes. For anyone who needs a reliable SSH connection, Mosh should be at the top of your list of tools. With this tool, you can even switch IP addresses and stay connected. Mosh works using UDP and a special synchronization protocol.

I’ll show you how to install and use Mosh.

What you need to make lasting SSH connections with Mosh

Mosh is installed on both the server and the client, so you need at least two machines to install it on. Mosh can be installed on Linux, macOS, Windows, Chrome/Chrome OS, Android and iOS. I’m going to demonstrate with Pop!_OS Linux as client and Ubuntu Server 22.04 as server. Aside from the installation, using Mosh is the same regardless of the operating system.

That said, let’s get to work.

How Mosh . to install

Remember you have to install Mosh on both desktop and server or it won’t work. So log into your desktop, open a terminal window and issue the command:

sudo apt-get install mosh -y

When that’s done, do the same on your server to install the app.

Once Mosh is installed, you will not find a GUI app on your desktop menu. Instead, Mosh is a command that runs, almost exactly like SSH. Let me show you.

How Mosh . to use

So we installed Mosh on both machines. Let’s make that lasting connection. On your desktop, go back to the terminal and issue the command:

mosh USER@SERVER

In this command, USER is the remote username and SERVER is the IP address of the server.

The connection is made exactly as it is with SSH. In fact, the only difference you’ll notice is using mosh instead of ssh.

If you are using a firewall, you may need to open the 60000:61000 ports. For example, with ufw, the commands for that would be:

sudo ufw allow 60000
sudo ufw allow 61000

If you use iptables, the commands are:

sudo firewall-cmd --zone=public --add-port=60000/udp
sudo firewall-cmd --zone=public --add-port=61000/udp

With firewall cmd you also need to reload the firewall with:

sudo firewall-cmd --reload

Mosh does everything in the background by transferring the binary stream of inputs and outputs between the two computers. It achieves this by synchronizing keystrokes and screens so that if the connection is interrupted, it can be easily resumed as both client and server remain in sync. And because Mosh only needs to buffer the keystrokes and the latest frame or screen, it can “pause” until the two machines are reconnected.

And that’s all there is to using Mosh. Enjoy those persistent SSH connections.

Subscribe to TechRepublic’s How to make technology work on YouTube for all the latest technical advice for business professionals from Jack Wallen.

Source link

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

0FansLike
3,692FollowersFollow
0SubscribersSubscribe

Latest Articles