MacOS – Why does ssh not detect disconnects

macosNetworkssh

If I SSH into a remote host on OS X, and then close the lid and travel home, upon opening the lid, OS X sometimes notes rather quickly that a disconnect has occurred (with the message "Broken pipe."), but often ssh just hangs. I thought of adding TCP keep-alives, however, the man page notes:

The default is "yes" (to send TCP keepalive messages), and the client will notice if the network goes down or the remote host dies.

Is there anything more I can do or check? Why does it work?

Best Answer

sysctl -w net.inet.tcp.always_keepalive=1

(or net.inet.tcp.always_keepalive=1 in /etc/sysctl.conf)