Live data from Hacker News

Closing a stale SSH connection

davidisaksson.dev

1–10 of 91 posts

Re: Closing a stale SSH connection

#3
Adding for completeness sake, if using Alpine Linux the ssh escape sequence menu and output will not display correctly if using /bin/ash from BusyBox as your login shell. One work-around is to type 'cat [Return]' and then use the escape sequences, or to carefully change your shell to /bin/bash

Re: Closing a stale SSH connection

#6
Pro tip: if you used ssh to get into host A and then another ssh to get from host A into host B, to break the A-B connection you need to issue `~~.`

("control up-arrow Q" song playing in the background.)

Re: Closing a stale SSH connection

#7
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 datacenter-wide diskless NFS clients and NAS's but I dont believe this will work with SSH due to session keys. As you alluded to, Mosh is the best current way to deal with broken or roaming sessions as Mosh uses a nonce and is designed to be stateless.

If the sshd and ssh client timeouts are high enough, a UDP VPN can at times work around intermittent timeouts.

Re: Closing a stale SSH connection

#8

Adding for completeness sake, if using Alpine Linux the ssh escape sequence menu and output will not display correctly if using /bin/ash from BusyBox as your login shell. One work-around is to type 'cat [Return]' and then use the escape sequences, or to carefully change your shell to /bin/bash

With all that glory of Alpine, my personal choice is to avoid having it on server side, it's too much "if" with it to keep in my memory.

Re: Closing a stale SSH connection

#10

Adding for completeness sake, if using Alpine Linux the ssh escape sequence menu and output will not display correctly if using /bin/ash from BusyBox as your login shell. One work-around is to type 'cat [Return]' and then use the escape sequences, or to carefully change your shell to /bin/bash

Alpine Linux user here, i could not reproduce that. How does the used shell even matter for that? The ssh client talks to the tty directly, not via shell.
Post reply on HN