Showing posts with label How to disconnect idle (after few minutes of inactivity) SSH sessions automatically. Show all posts
Showing posts with label How to disconnect idle (after few minutes of inactivity) SSH sessions automatically. Show all posts

Sunday, July 24

How to disconnect idle (after few minutes of inactivity) SSH sessions automatically
Uncomments the following two lines under /etc/ssh/sshd_config and restart the SSH services.
# vi /etc/ssh/sshd_config
ClientAliveInterval 300             
ClientAliveCountMax 0

ClientAliveCountMax – This indicates the total number of checkalive message sent by the SSH server without getting any response from the SSH client. Default is 3 but I’m going to set zero (0) to check this experiment.

ClientAliveInterval – This indicates the time-out in 5 seconds. After x number of seconds, ssh server will send a message to the client asking for response. Default is 0. If any response received from client, the session was killed automatically.

Restart the SSH services
# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
#

TEST:
Open new putty session for any user and wait for 5 min, you will get the following message:

Server sent disconnect message type 2 (protocol error): “Timeout, your session not responding.”