Live data from Hacker News

Closing a stale SSH connection

davidisaksson.dev

11–20 of 91 posts

Re: Closing a stale SSH connection

#11
I wish there is an easy way to have the reverse: a “sticky” ssh session.

It’s so annoying that the connection is lost when going to sleep or network issues. And the solutions to fix this are not really worth the effort.

Re: Closing a stale SSH connection

#12

I wish there is an easy way to have the reverse: a “sticky” ssh session. It’s so annoying that the connection is lost when going to sleep or network issues. And the solutions to fix this are not really worth the effort.

I’m not sure about resuming from sleep, but does mosh address your network stability issues?

https://mosh.org/

Re: Closing a stale SSH connection

#13

I wish there is an easy way to have the reverse: a “sticky” ssh session. It’s so annoying that the connection is lost when going to sleep or network issues. And the solutions to fix this are not really worth the effort.

I run ssh in a loop and auto-attach to a persistent tmux session on the other end. I also kill ssh processes as part of suspend so that the new one gets launched in the loop as soon as we wake up.

Re: Closing a stale SSH connection

#14
post #12

I wish there is an easy way to have the reverse: a “sticky” ssh session. It’s so annoying that the connection is lost when going to sleep or network issues. And the solutions to fix this are not really worth the effort.

I’m not sure about resuming from sleep, but does mosh address your network stability issues? https://mosh.org/

The main thing about Mosh is you need both on the sever and the client. Installing on random servers you might be ssh -in only once feels gross.

Re: Closing a stale SSH connection

#15
post #12

Earlier quoted context omitted.

I’m not sure about resuming from sleep, but does mosh address your network stability issues? https://mosh.org/

The main thing about Mosh is you need both on the sever and the client. Installing on random servers you might be ssh -in only once feels gross.

Has Mosh crypto been reviewed? Last I checked they were using some custom crypto on top of UDP instead of using something like DTLS or QUIC. Given SSH is one of the most battle tested protocols out there I am wary of replacing it with something else.

Re: Closing a stale SSH connection

#16
post #4

One of the most useful SSH tricks I've ever learned. I wonder if there's a way to detect a stale session and force reconnect when I turn on the computer? Like mosh[0], but with SSH. [0]: https://mosh.org/

I wonder if there's a way to detect a stale session and force reconnect SSH uses TCP and if the session is gone it will be an invalid session in iptables/nftables and likely have timed out on the remote end depending on state table timeouts and how long your laptop were offline. If there were no firewall in the path then one could play with long SO_KEEPALIVE sessions which I have done in the past when rebooting datac…

> "As you _eluded_ to"

should be "alluded to"; eluded: evaded / dodged, vs alluded to: mentioned / referred to

NOT being pedantic about spelling, just trying to be helpful (esp. for non-native English readers).

Re: Closing a stale SSH connection

#17
post #13

I wish there is an easy way to have the reverse: a “sticky” ssh session. It’s so annoying that the connection is lost when going to sleep or network issues. And the solutions to fix this are not really worth the effort.

I run ssh in a loop and auto-attach to a persistent tmux session on the other end. I also kill ssh processes as part of suspend so that the new one gets launched in the loop as soon as we wake up.

Check out autossh(1)!

Re: Closing a stale SSH connection

#18
post #13

Earlier quoted context omitted.

I run ssh in a loop and auto-attach to a persistent tmux session on the other end. I also kill ssh processes as part of suspend so that the new one gets launched in the loop as soon as we wake up.

Check out autossh(1)!

[1] https://github.com/Autossh/autossh

Re: Closing a stale SSH connection

#19
post #5

If you enjoyed this article, you may also find other useful tips in a piece I submitted to HN a while ago on "advanced SSH usage": https://johannes.truschnigg.info/writing/2022-07_advanced_ss...

If you enjoyed this article, you may like to learn about man pages... Try "man man".

Re: Closing a stale SSH connection

#20

Earlier quoted context omitted.

I wonder if there's a way to detect a stale session and force reconnect SSH uses TCP and if the session is gone it will be an invalid session in iptables/nftables and likely have timed out on the remote end depending on state table timeouts and how long your laptop were offline. If there were no firewall in the path then one could play with long SO_KEEPALIVE sessions which I have done in the past when rebooting datac…

> "As you _eluded_ to" should be "alluded to"; eluded: evaded / dodged, vs alluded to: mentioned / referred to NOT being pedantic about spelling, just trying to be helpful (esp. for non-native English readers).

Thanks. I'm sure I will get it wrong again but I try. Another one that my subconscious types out wrong is queue vs cue out of habit. Fixed in above comment.
Post reply on HN