I want to be able to automatically terminate ssh connections that are idle for more than 10 minutes.

How do I do this?


Open up terminal, Ctrl-Alt-T. Then:

  • sudo gedit /etc/ssh/sshd_config

  • Set (or modify) the following options:

    ClientAliveInterval 600
    ClientAliveCountMax 0
  • Save and exit the editor.

  • Run sudo service ssh restart

ClientAliveInterval sets the period after which, if the server sees the client as idle, it will send a "keep alive" request. If it gets no response, the client is disconnected. ClientAliveCountMax is the number of times such a keep alive is requested before disconnection. By setting it to 0, the keepalive is never sent and all clients idle for more than 10 minutes (600 seconds) are disconnected.


Edit /etc/ssh/sshd_config

sudo vim /etc/ssh/sshd_config

Add in this file the ClientAliveInterval option in seconds.

By the MAN page of sshd_config, that you can check here :

ClientAliveInterval: Sets a timeout interval in seconds after which if no data has been received from the client, sshd will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.