How to Install AutoSSH on Linux Mint 21

How to Install AutoSSH on Linux Mint 21

Are you looking for a tutorial on how to install AutoSSH on Linux Mint 21? Then this guide is for you.

Secure Shell, SSH for short, is a network protocol for secure remote access and control of another computer device or server over an unsecured network by authenticating using keys. Due to its provided encrypted channel, an outside can’t intercept the communication between the client and the server machine. 

However, an SSH connection may die or break, causing a disconnection during the session. This can be irritating in some situations. And that’s where AutoSSH comes into play. 

What is AutoSSH?

AutoSSH is a useful tool for maintaining continuous SSH connections. It monitors your SSH connection and restarts it upon disconnection. The inspiration is from rstunnel (Reliable SSH Tunnel). However, AutoSSH is built on C, whereas rstunnel is built on Shell. 

It sends packages every 10 minutes to test the connection. If it’s unable to do so, it will try to re-establish the connection. So if there was a disconnection due to poor network or Firewall blocking, the connection will automatically take place.

Behind the scenes, it works as follows:

It constructs an SSH forwarding loop from local to remote and from remote to local. Then it sends data, expecting some result in return. The data returned determines whether it will reconnect or not.

How to Install AutoSSH on Linux Mint 21

Now that you have some idea about what AutoSSH is and how it works, let’s see how you can install it on your Linux Mint device. We’ll cover two methods.

How to Install AutoSSH Using Command Line?

First, let’s update our system to make it ready to install new software. Update your system with this command:

$ sudo apt update && sudo apt upgrade

Output:

update system linux mint

After the process finishes, install AutoSSH by running this command:

$ sudo apt-get install autossh

Output:

How to Install AutoSSH on Linux Mint 21

It’s a small file and shouldn’t take long to get installed. To see if the installation was successful, you may check its version. To check the version, run this command:

$ autossh -V

Output:

autossh version

If you see a similar output as the above, that means you’ve successfully installed it.

How to Install AutoSSH Using Source File?

If you’re not comfortable with the terminal, then you can follow this method instead. We will download the source file and manually install it.

Follow this download link to get the TAR file on your computer. Choose a suitable place to save the file. The download should start.

Note: The link may not always work due to some restrictions on the site. In that case, use a good VPN and try again.

autossh download

Now navigate to the directory where you saved it. In our case, it’s ‘Downloads’, the default folder for downloaded stuff. Navigate using this command:

$ cd Downloads/

Then see if the file is there with this command:

$ ls

Output:

cd command

We’ve confirmed that the file is here. Now extract the TAR file by running this command:

$ gunzip -c autossh-1.4g.tgz | tar xvf -

Output:

How to Install AutoSSH on Linux Mint 21

By unzipping, a new directory was created. Check it with this command:

$ ls

Output:

ls command

Navigate into the autossh-1.4g directory with this command:

$ cd autossh-1.4g

Output:

cd into autossh

There are a few files inside the directory.

ls command

We need to execute the configure file. To do that, use the below command:

$ ./configure

Output:

How to Install AutoSSH on Linux Mint 21

Now recompile and build the application with the make command, like this:

$ make

Output:

How to Install AutoSSH on Linux Mint 21

Notice that there is an ‘autossh’ file that wasn’t there previously. 

ls command

This is the binary file. You may copy it to another place if you want or simply install it under /usr/local. We will go with the second option. To install the program, run this command:

$ sudo make install

Output:

How to Install AutoSSH on Linux Mint 21

Now, once again, let’s confirm if the installation was successful by checking its version. For that, run this command:

$ autossh -V

Output:

autossh version

We’ve successfully installed it from the source file.

How to Remove Autossh on Linux Mint 21?

If you didn’t like AutoSSH or don’t want to use it anymore, you can uninstall it. Removing AutoSSH is as easy as installing it. Simply remove it from your computer with this command:

$ sudo apt-get remove autossh

Output:

remove autossh

You can also remove the downloaded files and unzipped files with this command:

$ sudo rm -rf autossh-1.4g autossh-1.4g.tgz

Output:

remove autossh

This will remove both the TAR file and the unzipped directory with all the files it contains.

How to Use AutoSSH?

This is the basic syntax of AutoSSH:

$ autossh -M <port>[:echo_port] [-f] [SSH OPTIONS]

AutoSSH itself has only three different flags.

  • -M: for specifying the base monitoring port to use
  •  -f: For causing autossh to drop to the background before running ssh
  • -V: Display the current version and exit.

Here are some examples of using AutoSSH:

$ autossh -M 0 username@servername

Passing 0 to the -M flag means you’re turning off monitoring. This means AutoSSH will only restart SSH when you exit SSH.

To use a port as a monitoring port, you pass that as the argument. So to use 2000 as a monitoring port, use this command:

$ autossh -M 2000 username@servername 

The 2000 port will act as the forwarding port; meanwhile, the 2001 port will work as the receiving one. That’s because AutoSSH receives back data from one port above. This is why you should confirm that nothing is using the above port.

Final Thoughts

This tutorial shows you how to install AutoSSH on Linux Mint 21. We’ve shown two methods out of which you can pick any you’re comfortable with. We also covered some basics of SSH, and AutoSSH so that you can start using it right away.

That’s it for this post. If you’re stuck somewhere, feel free to let us know in the comments below.

If this guide helped you, please share it.

Related Posts