Keep SSH session alive while computer sleep? [closed]

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)