Mac OS X SSH Session Disconnection

By Xah Lee. Date:

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

The 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 man sshd_config.

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.


If you have a question, put $5 at patreon and message me.

  1. Unixer Plain-Text Email Fetish
  2. Unixers, RFC, and Perl
  3. Unix and the mbox Email Format
  4. Unix, RFC, Line Truncation
  5. Idiocy Of Unix Copy Command
  6. The Elements Of Style: UNIX As Literature
  7. On Unix Filename Characters Problem
  8. Unix And Literary Correlation
  9. What's the Max Number of Directories a Directory Can Have?
  10. Rob Pike on the Origin of Dot File Names
  11. Unix, Security, and FTP
  12. Is Mac OS X Unix?
  13. The Unix Pestilence: MySQL
  14. Mac OS X SSH Session Disconnection
  15. Mac OS X Changes To Unix
  16. On Microsoft Hatred