How to install Autossh on Ubuntu 16.04

How to install Autossh on Ubuntu 16.04

The Autossh is a program to start a copy of SSH sessions and monitoring it or restarting it, should the session die and stop the passing traffic. The autossh uses the SSH to construct a loop of SSH forwardings and then sends the test data that it expects to get back. This tutorial explains the installation procedure of Autossh on Ubuntu.

Installation procedure

To start the installation procedure, first add the repo and execute the following command.

root@linuxhelp1:~# add-apt-repository ppa:eugenesan/ppa
 This repository contains collection of customized, updated, ported and backported
packages for two last LTS releases and latest pre-LTS release.
Packages for older releases relocated to ppa:eugenesan/archive or deleted.

+-------------------------------------------------------------------------------------+
| Disclaimer:
+-------------------------------------------------------------------------------------+
* Packages in this a nd related PPAs are for personal use only.
  They developed specifically for several custom environments and may not work for you.
* Usage of packages in this PPA, in some forms, might contradict licenses of software
  packaged in this and related PPAs. End users and administrator are responsible for
  runtime licensing and possible legal consequences.
* Some packages provided with their dependencies while some might require additional
  Ubuntu repositories and external PPAs. Below is the list of

+-------------------------------------------------------------------------------------+
| To add this repository, to your Ubuntu installation, invoke:
+-------------------------------------------------------------------------------------+
$ sudo add-apt-repository ppa:eugenesan/ppa
.
.
.
gpg: keyring `/tmp/tmp6jp7grtr/secring.gpg'  created
gpg: keyring `/tmp/tmp6jp7grtr/pubring.gpg'  created
gpg: requesting key 8313A596 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp6jp7grtr/trustdb.gpg: trustdb created
gpg: key 8313A596: public key " Launchpad synergy+"  imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

The repositories is added successfully. Now update the repo of the target system by running the following command.

root@linuxhelp1:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease          
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://ppa.launchpad.net/eugenesan/ppa/ubuntu xenial InRelease [17.5 kB]                          
Get:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]                                        
Get:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]                                        
Get:6 http://ppa.launchpad.net/eugenesan/ppa/ubuntu xenial/main amd64 Packages [40.6 kB]             
Get:7 http://ppa.launchpad.net/eugenesan/ppa/ubuntu xenial/main i386 Packages [40.5 kB]             
Get:8 http://ppa.launchpad.net/eugenesan/ppa/ubuntu xenial/main Translation-en [24.7 kB]                                            
Fetched 430 kB in 8s (52.4 kB/s)                                                                                                    
Reading package lists... Done

The system is updated with the repositories. Then install the Autossh package by executing the apt-get install command and press y to continue with the installation.

root@linuxhelp1:~# apt-get install autossh -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  autossh
0 upgraded, 1 newly installed, 0 to remove and 480 not upgraded.
Need to get 27.4 kB of archives.
After this operation, 123 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 autossh amd64 1.4e-2 [27.4 kB]
Fetched 27.4 kB in 0s (53.7 kB/s)
Selecting previously unselected package autossh.
(Reading database ... 176594 files and directories currently installed.)
Preparing to unpack .../autossh_1.4e-2_amd64.deb ...
Unpacking autossh (1.4e-2) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up autossh (1.4e-2) ...


For using the Autossh, execute the following command to list the options that can be used with the Autossh.

root@linuxhelp1:~# autossh 
usage: autossh [-V] [-M monitor_port[:echo_port]] [-f] [SSH_OPTIONS]

    -M specifies monitor port. Overrides the environment
       variable AUTOSSH_PORT. 0 turns monitoring loop off.
       Alternatively, a port for an echo service on the remote
       machine may be specified. (Normally port 7.)
    -f run in background (autossh handles this, and does not
       pass it to ssh.)
    -V print autossh version and exit.

Environment variables are:
    AUTOSSH_GATETIME    - how long must an ssh session be established
                          before we decide it really was established
                          (in seconds). Default is 30 seconds  use of -f
                          flag sets this to 0.
    AUTOSSH_LOGFILE     - file to log to (default is to use the syslog
                          facility)
    AUTOSSH_LOGLEVEL    - level of log verbosity
    AUTOSSH_MAXLIFETIME - set the maximum time to live (seconds)
    AUTOSSH_MAXSTART    - max times to restart (default is no limit)
    AUTOSSH_MESSAGE     - message to append to echo string (max 64 bytes)
    AUTOSSH_PATH        - path to ssh if not default
    AUTOSSH_PIDFILE     - write pid to this file
    AUTOSSH_POLL        - how often to check the connection (seconds)
    AUTOSSH_FIRST_POLL  - time before first connection check (seconds)
    AUTOSSH_PORT        - port to use for monitor connection
    AUTOSSH_DEBUG       - turn logging to maximum verbosity and log to
                          Stderr


To remove the Autossh, execute the following command and press y to continue with the uninstallation.

root@linuxhelp1:~# apt-get remove autossh -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  autossh
0 upgraded, 0 newly installed, 1 to remove and 480 not upgraded.
After this operation, 123 kB disk space will be freed.
(Reading database ... 176614 files and directories currently installed.)
Removing autossh (1.4e-2) ...
Processing triggers for man-db (2.7.5-1) ...

Wasn' t that an easy installation procedure? The Autossh tries to avoid congestion in the traffic by making sure all the port numbers on the remote machines does not collide.

Tag : SSH Ubuntu
FAQ
Q
where to run the autossh in ubuntu?
A
execute the following command to list the options that can be used with the Autossh.
# autossh
Q
how to add the repo of Autossh on ubuntu?
A
add the repo and execute the following command.
# add-apt-repository ppa:eugenesan/ppa
Q
How to unmerge the autossh in ubuntu?
A
use the following command to unmerge the autossh in ubuntu # emerge --ask --unmerge net-misc/autossh
Q
What is AutoSSH?
A
Autossh is a program to start a copy of ssh and monitor it, restarting it as necessary should it die or stop passing traffic.
Q
How to AutoSSH during boot with systemd?
A
If you want a permanent SSH tunnel already created during boot time, you will (nowadays) have to create a systemd service and enable it. There is however an important thing to note about syst