LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2016, 03:26 AM   #1
The_Linux_Machine
LQ Newbie
 
Registered: Jul 2016
Posts: 3

Rep: Reputation: Disabled
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.
 
Old 07-05-2016, 02:52 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Do you have NetworkManager-wait-online.service enabled?

Very likely the network was NOT ready.
 
Old 07-05-2016, 05:08 PM   #3
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
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.

Last edited by dijetlo; 07-05-2016 at 05:09 PM.
 
Old 07-06-2016, 03:21 AM   #4
The_Linux_Machine
LQ Newbie
 
Registered: Jul 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
The NetworkManager.service is enabled.
 
Old 07-06-2016, 05:29 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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...

Last edited by jpollard; 07-06-2016 at 05:32 AM.
 
Old 07-06-2016, 11:36 PM   #6
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
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.
 
  


Reply

Tags
systemd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Postgresql service does not start when boot thach.trung.ngoc Slackware 2 03-26-2012 06:00 AM
service won't start at boot jgonsalves Linux - Newbie 9 05-26-2010 08:42 AM
How to get service to start at boot zaichik Linux - Newbie 12 08-27-2008 09:15 PM
BOINC as a service to start at boot purelithium Linux - General 14 11-18-2005 09:04 PM
how to start a service at boot senthilkumar Slackware 2 07-19-2004 07:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration