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?

  • As they say: It takes two to tango, so no mater if you keep the mac side up and alive, since the other side is down, the whole thing is down.
    – Ruskes
    Commented Mar 21, 2014 at 15:22

2 Answers 2

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

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


If you travel from your office to your home, your MacBook will be disconnected from any network.

Even if ssh sent a keepalive, it would not be received by the server (because your computer is offline).

The best thing you can do: quit your ssh session before traveling, it will at least avoid ssh hangs.

  • The man page notes "the client will notice if the network goes down" — even when the network is back up (it usually only takes a few seconds after opening the lid), it still doesn't notice that the connection is dead.
    – Thanatos
    Commented Mar 23, 2014 at 2:47
  • Maybe will it notice only if the terminal is running. In sleep mode, the client may not be able to detect that network has gone down.
    – lauhub
    Commented Mar 23, 2014 at 10:13
  • I expect that it wouldn't notice when the lid is closed and the laptop is asleep. But once the lid has been reopened and the system is alive again… shortly after the next TCP keepalive hits the wire, we should be realizing the connection is dead, no?
    – Thanatos
    Commented Mar 23, 2014 at 20:26
  • Maybe this is a bug. If you submit a bug report at bugreport.apple.com they will indicate if this is a known problem or not.
    – lauhub
    Commented Mar 26, 2014 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .