Live data from Hacker News

Autossh – automatically restart SSH sessions and tunnels

github.com

31–40 of 90 posts

Re: Autossh – automatically restart SSH sessions and tunnels

#31
post #18
post #11

Earlier quoted context omitted.

[flagged]

Do we really still have to turn every conversation into systemd friction?

No. Some people use ssh while not running Linux, and not by running something exotic; macOS is widely popular.

Re: Autossh – automatically restart SSH sessions and tunnels

#32
post #6

If you have systemd, you could do this: [Unit] Description=look ma, no autossh After=network.target [Service] Type=exec ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -Nn -R 7070:localhost:22 pc 'sleep 20m' Restart=always RestartSec=20 RuntimeMaxSec=30m [Install] WantedBy=default.target

No passphrase for the key? What about spotty connection? Doesn't WantedBy block startup on this starting properly? (I'm pretty sure I've been soft locked out of my computer when Comcast decides to do Comcast things.

Re: Autossh – automatically restart SSH sessions and tunnels

#33
Use stunnel for non-interactive tunneling over TLS.

It is much more straightforward than ssh for this purpose, and works well with socket activation under systemd.

I use it with the systemd automounter to encrypt NFSv4, and I have found it to be quite reliable.

Re: Autossh – automatically restart SSH sessions and tunnels

#34
post #6

If you have systemd, you could do this: [Unit] Description=look ma, no autossh After=network.target [Service] Type=exec ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -Nn -R 7070:localhost:22 pc 'sleep 20m' Restart=always RestartSec=20 RuntimeMaxSec=30m [Install] WantedBy=default.target

I think this is actually superior to autossh. Doesn’t autossh not restart after crash/reboot?

Re: Autossh – automatically restart SSH sessions and tunnels

#35
Sometime back, I had a rapsberry pi connected to wired network of a coworking space. I remember using autossh to keep a tunnel open with one of my VPS. Mainly used it as a torrent box. I added magnet links through qbittorrent webui installed on raspberry pi. Qbittorrent was configured to only run at night time to not cause issues for business work. Downloaded all sort of things easily reaching thousands of GBs throughout my time there. They never found out. Or they didn't care to look. Good times.

Re: Autossh – automatically restart SSH sessions and tunnels

#36
post #6

If you have systemd, you could do this: [Unit] Description=look ma, no autossh After=network.target [Service] Type=exec ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -Nn -R 7070:localhost:22 pc 'sleep 20m' Restart=always RestartSec=20 RuntimeMaxSec=30m [Install] WantedBy=default.target

No passphrase for the key? What about spotty connection? Doesn't WantedBy block startup on this starting properly? (I'm pretty sure I've been soft locked out of my computer when Comcast decides to do Comcast things.

No. WantedBy will have no impact on startup. Before or after would, but not Wantedby.

Re: Autossh – automatically restart SSH sessions and tunnels

#37
post #6

If you have systemd, you could do this: [Unit] Description=look ma, no autossh After=network.target [Service] Type=exec ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -Nn -R 7070:localhost:22 pc 'sleep 20m' Restart=always RestartSec=20 RuntimeMaxSec=30m [Install] WantedBy=default.target

I think this is actually superior to autossh. Doesn’t autossh not restart after crash/reboot?

It doesn't by default, but you can set the AUTOSSH_GATETIME environment variable to 0 so that autossh retries even if the first connection attempt fails.

Re: Autossh – automatically restart SSH sessions and tunnels

#38
post #6

If you have systemd, you could do this: [Unit] Description=look ma, no autossh After=network.target [Service] Type=exec ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -Nn -R 7070:localhost:22 pc 'sleep 20m' Restart=always RestartSec=20 RuntimeMaxSec=30m [Install] WantedBy=default.target

been doing this since 2012... autossh wasn't the solution back then even.

you want ServerAliveCountMax too but default is 3.

Re: Autossh – automatically restart SSH sessions and tunnels

#39
I use this to set up reverse tunnels, for example to set up MongoDB replica sets which sync through SSH. It kind of simplifies the security aspect of replica sets a bit, since then MongoDB does not need to be exposed to the internet and no VPN setup is needed.
Post reply on HN