LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   AUTOSSH.service does not start at boot, how can I fix this? (https://www.linuxquestions.org/questions/linux-networking-3/autossh-service-does-not-start-at-boot-how-can-i-fix-this-4175583801/)

The_Linux_Machine 07-05-2016 03:26 AM

AUTOSSH.service does not start at boot, how can I fix this?
 
Hello everyone, I am trying to set up a connection (via SSH) that is always on (persistent).

As a result I have created a autossh.service file (on my computer running Kali Linux 2016.1) in this directory /lib/systemd/system/autossh.service, here is the contents of the autossh.service file:

[Unit]
Description=AutoSSH service for a reverse tunnel from some.example.com to localhost
After=network.target

[Service]
ExecStart=/usr/bin/autossh -M 0 -q -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 6111:localhost:22 My_Server_IP

[Install]
WantedBy=default.target

After creating that file I have run systemctl daemon-reload, then systemctl start autossh.

As you can see the output from systemctl status autossh:

● autossh.service - AutoSSH service for a reverse tunnel from some.example.com to localhost
Loaded: loaded (/lib/systemd/system/autossh.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2016-07-05 16:20:43 MYT; 7s ago
Main PID: 2014 (autossh)
Tasks: 2 (limit: 512)
CGroup: /system.slice/autossh.service
├─2014 /usr/lib/autossh/autossh -M 0 -q -N -o ServerAliveInterval 60 -o ServerAliveCountMax 3 -R 6111:localhost:22 188.166.216.239
└─2018 /usr/bin/ssh -q -N -o ServerAliveInterval 60 -o ServerAliveCountMax 3 -R 6111:localhost:22 188.166.216.239

Jul 05 16:20:43 unity systemd[1]: Started AutoSSH service for a reverse tunnel from some.example.com to localhost.
Jul 05 16:20:43 unity autossh[2014]: port set to 0, monitoring disabled
Jul 05 16:20:43 unity autossh[2014]: starting ssh (count 1)
Jul 05 16:20:43 unity autossh[2014]: ssh child pid is 2018

The autossh.service has been started manually, my next step will be to type in
systemctl enable (so that autossh.service can be run, even if the computer restarts or is shutdown.

When I reboot my computer, and type in systemtctl status autossh, I get this output:

● autossh.service - AutoSSH service for a reverse tunnel from some.example.com to localhost
Loaded: loaded (/lib/systemd/system/autossh.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2016-07-05 16:25:03 MYT; 1s ago
Process: 2014 ExecStart=/usr/bin/autossh -M 0 -q -N -o ServerAliveInterval 60 -o ServerAliveCountMax 3 -R 6111:localhost:22 188.166.216.239 (code=exited, status=0/SUCCESS)
Main PID: 2014 (code=exited, status=0/SUCCESS)

Jul 05 16:20:43 unity systemd[1]: Started AutoSSH service for a reverse tunnel from some.example.com to localhost.
Jul 05 16:20:43 unity autossh[2014]: port set to 0, monitoring disabled
Jul 05 16:20:43 unity autossh[2014]: starting ssh (count 1)
Jul 05 16:20:43 unity autossh[2014]: ssh child pid is 2018
Jul 05 16:25:03 unity systemd[1]: Stopping AutoSSH service for a reverse tunnel from some.example.com to localhost...
Jul 05 16:25:03 unity systemd[1]: Stopped AutoSSH service for a reverse tunnel from some.example.com to localhost.

The autossh.service unit file had failed to load, please tell me how I can fix this.

jpollard 07-05-2016 02:52 PM

Do you have NetworkManager-wait-online.service enabled?

Very likely the network was NOT ready.

dijetlo 07-05-2016 05:08 PM

Quote:

Jul 05 16:20:43 unity autossh[2014]: port set to 0
The zeros are the unix sockets... I think you probably want a standard port there, 22 springs to mind...

Which doesn't obviate the need for a functioning network visa vis J Pollards point.

The_Linux_Machine 07-06-2016 03:21 AM

The NetworkManager.service is enabled.

jpollard 07-06-2016 05:29 AM

NetworkManager-wait-online.service is not the same as NetworkManager.service.

All NetworkManager.service does is start NetworkManager.

It does NOT guarantee the network is usable when Network.target is reached - just that the INITIALIZATION of the network has been started.

The problem with NetworkManager is that it doesn't tell systemd things are working... NetworkManager had to be modified by adding internal messages to tell systemd the network is functional - and that is tested by NetworkManager-wait-online.service.

Even then, I'm not sure it is guaranteed - DHCP can take a LONG time to obtain network configuration. I'm not sure these services have been modified yet to tell NetworkManager when they are setup. Normally they just run, and keep running to handle expired leases, so unless DHCP handling has been modified there isn't a way for NetworkManager to know if the network is usable...

Static IP setup works fine this way - but you have to have NetworkManager-wait-online.service enabled or applications that require the network may fail... sometimes...

This is the same problem with databases - starting a database doesn't mean systemd waits for it to complete its setup, and that leaves other services depending on them in the lurch - unless the database has been modified by adding systemd components...

Doug G 07-06-2016 11:36 PM

I set up a similar autossh reverse tunnel on centos7. I don't recall all the details, but I do remember fiddling for some time to get it working.

Some differences I used: I used my own service name for systemd rather than autossh (created a new service file in /etc/systemd/system/. I created a new user account, created a ssh key for the new user, and used the -i option to specify the identity key location. I also use a monitor port rather than -M 0

This setup has run for months without me touching the configuration.


All times are GMT -5. The time now is 08:11 PM.