Is it possible to keep SSH session alive while computer sleep? When I put my Mac (Lion) to sleep for a short period of time and then wake it up session still alive, but if I leave it overnight session connection is closed.
I’ve tried set:
ClientAliveInterval 3600 ClientAliveCountMax 10
same result
Why session “survive” for a short period of time? How can I control this timeout?
I found the answer it depends on tcp keepalive settings:
For the list of available TCP settings (FreeBSD 4.8 an up and 5.4):
net.inet.tcp.keepidle– Amount of time, in milliseconds, that the (TCP) connection must be idle before keepalive probes (if enabled) are sent.net.inet.tcp.keepintvl– The interval, in milliseconds, between keepalive probes sent to remote machines. After TCPTV_KEEPCNT (default 8) probes are sent, with no response, the (TCP)connection is dropped.net.inet.tcp.always_keepalive– Assume that SO_KEEPALIVE is set on all TCP connections, the kernel will periodically send a packet to the remote host to verify the connection is still up.Therefore formula to calculate maximum TCP inactive connection time is following:
the result is in milliseconds. Therefore, by setting
the system will disconnect a call when TCP connection is dead for:
10000 + (5000 x 8) = 50000msec (50 sec). To make system remember these settings at startup, you should add them to/etc/sysctl.conffile