How to stop being logged out of SSH sessions when locking the screen in OS X 10.9.1?

It really depends on what is logging you out. Assuming that this is not an issue of changing Power settings (i.e. your machine is not sleeping), then most things that will break the connection can be solved by using a program called autossh.

It's a wrapper around the regular ssh program (which it uses) and it implements a more robust keep-alive mechanism.

I got mine from MacPorts, but I'm sure Fink has a port, too.


Two methods…

  • Add the following to /etc/ssh_config:

    TCPKeepAlive yes
    
  • Use screen:

    1. Create a new screen with screen, then use the terminal normally.
    2. When the connection breaks, reconnect normally.
    3. Run screen -dr to reattach.