3

I’m using Amazon Linux,

[davea@mymachine ~]$ uname -a
Linux mymachine.mydomein.org 4.4.35-45.83.amzn1.x86_64 #1 SMP Wed Jul 27 22:37:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

In my /etc/ssh/sshd_config, I have no value set for “ServerAliveInterval”. In this answer — What options `ServerAliveInterval` and `ClientAliveInterval` in sshd_config exactly do? , they say “Setting a value of 0 (the default) will disable these features so your connection could drop if it is idle for too long”. What does that mean? In precise terms, what is the default amount of time the connection will stay alive if this parameter is committed? Assume that I have set a value of “1000000000000” on the client side.

Dave
  • 2,548

2 Answers2

7

The value for ServerAliveInterval means that "if no data has been received from the server within this time then send a NULL message to the server".

Similarly, ClientAliveInterval means that "if no data has been received from the client within this time then send a NULL message to the client".

The default values are typically 0 which means these functions are disabled.

The main use of this is to prevent intermediate routers and firewalls from thinking a session is idle, and dropping it. It has no real impact on an ssh server, itself.

For example, many home NATting routers will drop idle sessions after a period of time (the exact time depends on your router; I've seen values from 1 hour to over 21 days). By setting the ServerAliveInterval you fake out this idle timeout in the router by making sure there's always some traffic within the router interval.

guettli
  • 1,389
  • So does setting "ServerAliveInterval" to a lower value (e.g. "5") mean that the connection will be kept alive every 5 seconds, even if the server is not sending back any data to the client? – Dave Sep 20 '16 at 16:33
  • If you set it to 5 then "if the server has not sent any data for 5 seconds then the client will send a NULL message to the server". So it will send a packet only if the server has not sent any data. – Stephen Harris Sep 20 '16 at 16:34
  • I've seen sessions drop after about 10 minutes of inactivity. – Joachim Wagner Feb 23 '24 at 11:10
0

In addition to the accepted answer, note that setting ServerAliveInterval to one trillion as in your question may cause an error "invalid time value" on 32-bit OpenSSH clients. While I don't have a 32-bit client at hand to test this, I do get this error message when setting the interval to 2^63 = 9223372036854775808 or higher with my 64-bit client.

A trillion seconds would be over 31709 years. If you don't want server alive message to be sent, just leave it at the default setting 0 which switches off this feature.

Furthermore, given the information in the accepted answer, you probably want to set ServerAliveInterval lower than 3600 if you want to use this feature.