You are not logged in.

#1 2013-10-16 16:06:40

anthillsocial
Member
Registered: 2013-02-18
Posts: 110

Setting up autossh as systemd service not working

I'm attempting to setup a reverse ssh tunnel using systemd. However the service I have created below doesn't seem to be opening the connection. #NOTE for obvious reasons I've changed the actual server I'm connecting to with 'user@remoteserver.com'.

The key based authentication works with the user ''tunneluser" so I've my suspicions that the connection may not be working because the autossh command 'might' not be running as tunneluser, though I'm not sure so I would really appreciate some tips.

[Unit]
Description=AutoSSH service for a reverse ssh tunnel
After=network.target

[Service]
User=tunneluser
ExecStart=/usr/bin/autossh autossh -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 223344:localhost:80 user@remoteserver.com

[Install]
WantedBy=multi-user.target
$ sudo systemctl status autossh.service -l
-------------------------------------------
autossh.service - AutoSSH service for a reverse ssh tunnel
   Loaded: loaded (/etc/systemd/system/autossh.service; enabled)
   Active: inactive (dead) since Wed 2013-10-16 13:47:28 GMT; 9s ago
  Process: 1796 ExecStart=/usr/bin/autossh autossh -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 223344:localhost:80 user@remoteserver.com (code=exited, status=0/SUCCESS)
 Main PID: 1796 (code=exited, status=0/SUCCESS)

Oct 16 13:47:28 MobileServer systemd[1]: AutoSSH service for a reverse ssh tunnel
Oct 16 13:47:28 MobileServer autossh[1796]: port set to 0, monitoring disabled

Last edited by anthillsocial (2013-10-16 16:31:46)

Offline

#2 2013-10-30 14:40:11

radarstreet
Member
Registered: 2013-10-30
Posts: 1

Re: Setting up autossh as systemd service not working

Hey,

I found this link to be very useful http://blog.philippklaus.de/2013/03/sta … rch-linux/
Anywho here is what I have in my service file:


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

[Service]
ExecStart=/usr/bin/autossh -M 0 -q -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" user@remoteserver -R 2222:localhost:22 -i /home/user/.ssh/id_rsa

[Install]
WantedBy=multi-user.target


I had trouble with the -f flag, so I dropped it...

Also I needed to run the autossh command as root first to confirm the authenticity of my remote server.

I hope this helps a little bit.

P.S. Sorry for lack of mark up, but this is my first post and I do not know the mark up of these forums yet...

Last edited by radarstreet (2013-10-30 14:45:15)

Offline

Board footer

Powered by FluxBB