Live data from Hacker News

Autossh – automatically restart SSH sessions and tunnels

github.com

81–90 of 90 posts

Re: Autossh – automatically restart SSH sessions and tunnels

#81

Curious what advantages this has over mosh? https://mosh.org/

Biggest issue i have with mosh is that it you cant scroll up the history. It is kind of a deal breaker for me.

hence why most throw in tmux/screen on the other end, possibly automatically so:

https://github.com/blinksh/blink/discussions/1526

Re: Autossh – automatically restart SSH sessions and tunnels

#82
post #67
post #28

Earlier quoted context omitted.

This approach works very well. I've had dozens of extremely remote systems hooked up this way for about 8 years. The only problem I've seen is that occasionally the server ssh process will get stuck, so you have to log in to the server and kill it. It seems to happen when a remote goes offline and reconnects without closing the old connection first. If I were doing it now, I'd probably use wireguard, probably. This i…

> ssh process stuck systemd's RuntimeMaxSec should help in this case but I've never had trouble with sshd personally To add more context I use the above service to ssh from my phone to my laptop via my desktop PC. The service runs on my laptop and binds port 22 of my laptop to port 7070 of my PC but wiregaurd would probably work similarly

RuntimeMaxSec would have systemd kill a live forwarded connection though?

Re: Autossh – automatically restart SSH sessions and tunnels

#83
post #28
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

This approach works very well. I've had dozens of extremely remote systems hooked up this way for about 8 years. The only problem I've seen is that occasionally the server ssh process will get stuck, so you have to log in to the server and kill it. It seems to happen when a remote goes offline and reconnects without closing the old connection first. If I were doing it now, I'd probably use wireguard, probably. This i…

> The only problem I've seen is that occasionally the server ssh process will get stuck, so you have to log in to the server and kill it.

You also need ClientAliveInterval on the server side (in addition to ServerAliveInterval on the client). In other words, both the client and the server need to be configured to monitor the connection. With this setup I had no issues with reconnections.

Re: Autossh – automatically restart SSH sessions and tunnels

#84
post #82
post #67

Earlier quoted context omitted.

> ssh process stuck systemd's RuntimeMaxSec should help in this case but I've never had trouble with sshd personally To add more context I use the above service to ssh from my phone to my laptop via my desktop PC. The service runs on my laptop and binds port 22 of my laptop to port 7070 of my PC but wiregaurd would probably work similarly

RuntimeMaxSec would have systemd kill a live forwarded connection though?

closing ssh doesn't close the ports if they are being used, at least with ControlMaster. You need to run something like this to force the ssh daemon to close the port

    ssh -O cancel -L 4102:localhost:4000 pc
but if ControlMaster is stuck maybe autossh is better in that case, or use this:

    Host *
        ServerAliveInterval 11

Re: Autossh – automatically restart SSH sessions and tunnels

#86
post #29
post #22

Nice tool, but I'm getting tired of using port numbers for everything instead of more descriptive strings. My system has more than 10 tunnels and servers running, and since I only do sysadmin work once every half year or so, the port numbers are very cumbersome to deal with.

I believe these days SSH is willing to forward a UNIX domain socket to a remote TCP port, or a local TCP port to a remote UNIX domain socket, or any combination of the two families really. You could use names locally, if your client tools are willing to do AF_UNIX!

And if you are wondering, if you can just point your browser to a local unix socket (without setting up a proxy - which will listen on... local tcp port), then no, but maybe some day?

Anyway:

- https://bugzilla.mozilla.org/show_bug.cgi?id=1688774 - [open] "Support HTTP over unix domain sockets" - 4 years old, last activity 7 months ago,

- https://issues.chromium.org/issues/40402523 - [closed; won't fix] "[ENH] Support HTTP over Unix Sockets via http://localhost:[/tmp/socket]/foo convention " - 9 years old, last activity 11 months ago.

Re: Autossh – automatically restart SSH sessions and tunnels

#87
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

Ok now how to tell if the connection is running in the systemd status output? Cos this will show as active even when the connection is down or trying to reconnect.

Re: Autossh – automatically restart SSH sessions and tunnels

#88
post #68

Earlier quoted context omitted.

I haven’t revisited this issue in years but on a project for thousands of similar devices we found autossh much more reliable. I believe the issue is that the connections often fail or get wedged in other network layers; the only way to be sure that your ssh tunnel isn’t: a) lossy enough to “keep alive” but too lossy to send data, or b) isn’t just always waiting on TCP retry backoff, or c) etc, is to use the tunnel t…

> is to use the tunnel to transmit actual data at the application level. Isn't that exactly what ServerAliveInterval does? The man page says: "ssh(1) will send a message through the encrypted channel". A plain TCP keepalive wouldn't count as being "through the encrypted channel".

Honestly at this point Im out of date, but autossh also takes care of bugs or connection issues within the ssh link itself

Re: Autossh – automatically restart SSH sessions and tunnels

#89
post #88

Earlier quoted context omitted.

> is to use the tunnel to transmit actual data at the application level. Isn't that exactly what ServerAliveInterval does? The man page says: "ssh(1) will send a message through the encrypted channel". A plain TCP keepalive wouldn't count as being "through the encrypted channel".

Honestly at this point Im out of date, but autossh also takes care of bugs or connection issues within the ssh link itself

So does ssh now.

So much smoke & obfuscation. Autossh itself mentions ServerAliveInterval. It's worked flawlessly on all kinds of dodgy connections for me.

If anyone has any damned bug reports, link them.

Re: Autossh – automatically restart SSH sessions and tunnels

#90
post #88

Earlier quoted context omitted.

Honestly at this point Im out of date, but autossh also takes care of bugs or connection issues within the ssh link itself

So does ssh now. So much smoke & obfuscation. Autossh itself mentions ServerAliveInterval. It's worked flawlessly on all kinds of dodgy connections for me. If anyone has any damned bug reports, link them.

I don't know if I would call it smoke and obfuscation, at the time systemd was not widely deployed and the ssh functionality was not as developed, so it made sense to use autossh. Now it sounds like it doesn't make sense anymore. It happens.
Post reply on HN