You are not logged in.

#1 2016-04-12 01:01:22

Peregrino69
Member
Registered: 2016-03-11
Posts: 37

[SOLVED] Autossh failing

More weirdity...

I'm running a permanent reverse SSH tunnel to RasPI at home using autossh. To have it starting automatically without logging in on Waldorf I just added this to /etc/rc.local:

# Start autossh script, output errors to log
/home/pgrino69/bin/raspitunnel > /home/pgrino69/log/raspitunnel.log 2>%1

The actual script is:

#!/bin/bash

set +e
SSH_OPTIONS=" -i /home/pgrino69/.ssh/id_rsa"

export AUTOSSH_GATETIME=0
export AUTOSSH_PORT=0

nohup autossh -f -- $SSH_OPTIONS -o 'ControlPath none' -R 15069:localhost:22 pgrino69@raspi1 -N 2> /home/pgrino69/logs/autossh_errors.log

exit 0

Now I'm trying to do the same on BL, only diff is the port number. And that fails. Autossh starts nicely, but RasPI won't start listening. If I run the script after login, it works just fine. I tried to stick this to /etc/init.d/, no luck. 

What on earth??? Do I have to figure out how to do this as systemd service???

Last edited by Peregrino69 (2016-04-18 17:25:58)

Offline

#2 2016-04-12 03:58:27

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: [SOLVED] Autossh failing

Yeah that kind of sucks about systemd. I went through a ton of headaches figuring out how to automount a sshfs mount. I finally figured out that the easiest way to go about it is to set it up in /etc/fstab. Systemd will then figure out the .mount and .automount unit files for you. For network mounts, be sure the _netdev option in /etc/fstab is listed. I have a post in Scripts, Tutorials and Tips where I built the mount points up as unit files but that method was considerably buggy. /etc/fstab was a better option though gvfs seemed to pick up the fuser mount and I would end up with a double mount. Plus, Debian does not seem to do well with the _netdev specifier in /etc/fstab. It does not unmount any network shares prior to shutdown which leaves you with a hung service for a minute and a half on each shutdown.

It would appear that I have lost the /etc/fstab stuff when my sid system blew up recently. I will have to rebuild it and push updates out go both git and the walkthrough I have posted on these forums.

The arch wiki should be a good place to start if you intend to go this route. I am pretty sure in a systemd system you will be unable to automatically mount stuff outside of the context of systemd. I mean, you can manually mount ssh stuff via terminal but automounting is not as simple as just executing said script. Also, getting keys to work is just a full on headache.

Last edited by tknomanzr (2016-04-12 04:00:59)

Offline

#3 2016-04-12 19:06:43

Peregrino69
Member
Registered: 2016-03-11
Posts: 37

Re: [SOLVED] Autossh failing

Oki, so I need to figure out systemd services. This isn't a network share, this is just a permanent tunnel - I'd assume you don't mount those even with systemd smile

Thanks.

BTW it'd be nice if you linked the post you're referring to smile

Offline

#4 2016-04-12 19:27:44

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: [SOLVED] Autossh failing

Peregrino69 wrote:

Do I have to figure out how to do this as systemd service???

Yup.

big_smile

Here's your starter for 10:

# /etc/systemd/system/raspitunnel.service
[Unit]
Description=Raspberry Pi ssh tunnel
Wants=network.target
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/bin/sh -c '/home/pgrino69/bin/raspitunnel > /home/pgrino69/log/raspitunnel.log 2>%1'

[Install]
WantedBy=multi-user.target

I'm sure you can do better...

See systemd.unit(5) & systemd.service(5)

To start the .service on boot, use:

sudo systemctl enable raspitunnel

To stop it, use:

sudo systemctl disable raspitunnel

See systemctl(1)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#5 2016-04-12 19:52:32

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: [SOLVED] Autossh failing

Hmm sorry. I intended to link it. Here it is:
https://forums.bunsenlabs.org/viewtopic.php?id=1256
Also, I still kind of feel like you are gonna want to translate this into /etc/fstab but I could be wrong! Let me know how it works out for you or if you need any help. Whether you call it a tunnel or not, systemd is gonna see it as a network mount, I think.

Offline

#6 2016-04-13 23:49:03

Peregrino69
Member
Registered: 2016-03-11
Posts: 37

Re: [SOLVED] Autossh failing

Sorry HoaS. I copied your script exactly, and didn't work.

tknomanzr, thanks for the tip smile This one isn't for mounting remote FS, just strictly for SSHing from one network to another using a middleman. But I'll keep that in mind, it'll be useful elsewhere smile

Offline

#7 2016-04-14 06:22:16

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: [SOLVED] Autossh failing

Peregrino69 wrote:

Sorry HoaS. I copied your script exactly, and didn't work.

Yeah, I didn't really think it would work OOTB, I cobbled that together in about two minutes big_smile

EDIT: try changing "Type=oneshot" to "Type=dbus" (sorry, I just can't help myself sometimes)

"didn't work" is a bit vague -- if you have a look at the output of:

systemctl status raspitunnel.service
sudo journalctl -u raspitunnel.service

You will be able to see how it fails and figure out how to get it working, if you're interested.

Alternatively, use:

sudo systemctl enable rc.local

I think this should allow you to use the old-style scripts in /etc/rc.local

Last edited by Head_on_a_Stick (2016-04-14 06:23:41)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#8 2016-04-14 12:14:30

Peregrino69
Member
Registered: 2016-03-11
Posts: 37

Re: [SOLVED] Autossh failing

Thanks HoaS. I should know better than saying "didn't work"...

I'll check these when I get my RasPI running again. Installed OpenVPN server, after which it won't accept SSH access anymore...

Offline

#9 2016-04-18 17:25:38

Peregrino69
Member
Registered: 2016-03-11
Posts: 37

Re: [SOLVED] Autossh failing

Resolved by simply putting the command to crontab.

@reboot /home/pgrino69/scripts/raspitunnel.sh

I first misplaced the script by doing nano /etc/crontab, which worked as well. /etc/crontab is a system-wide crontab file. Out of curiosity, what's the actual diff by editing that file instead of doing crontab -e?

Offline

Board footer

Powered by FluxBB