Keep SSH session alive while computer sleep?
ssh, timeout
Solution
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):
sysctl -A | grep net.inet.tcp
`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:
net.inet.tcp.keepidle + (net.inet.tcp.keepintvl x 8)
the result is in milliseconds. Therefore, by setting
net.inet.tcp.keepidle = 10000
net.inet.tcp.keepintvl = 5000
net.inet.tcp.always_keepalive = 1 (must be 1 always)
the system will disconnect a call when TCP connection is dead for: `10000 + (5000 x 8) = 50000` msec (50 sec). To make system remember these settings at startup, you should add them to `/etc/sysctl.conf` file
Problem
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?