Mac OS X SSH Session Disconnection
SSH Session Drops Idle Connection
One annoying thing about OS X is that, if you connect to it thru ssh, after some short period of inactivity, it logs you out. This is a pain in the ass for sys admin. This is actually not caused by OS X, nor ssh settings, but somewhere in the network some software or device auto disconnect when the connection is idle for some period of time.
Here's a trick to solve this problem.
Edit the file
/etc/sshd_config, so you have the lines:
ClientAliveInterval 280 ClientAliveCountMax 3
ClientAliveInterval means the number of seconds to check if client is alive, by sending client a encrypted message. Every n seconds, sshd will check if client is active. If client does not respond, it adds a count. When this count reaches
ClientAliveCountMax, sshd disconnect the client. You can read more by
You may need to restart ssh. You can do it by going to Control Panel, Sharing, uncheck the “Remote Login” line, then check again.
In traditional unix, you make sshd reread the config file by sending SIGHUP to ssh. (see
man sshd). For example:
ps auwwx | grep ssh kill -s HUP pid
However, i don't think that works in OS X, because when there is no connection, sshd isn't running. When there is a connection, and if you do
ps auwwx | grep ssh, you'll see that it starts with “-i” option, which means it is running thru inetd. This means, sshd by default in os x is actually not running as a dedicated server, but only launched when there is a connection.
Ask me question on patreon