How do I enable auto-logout of Interactive ssh logins after one hour
Solution 1
I already encountered situations where ClientAliveCountMax
prevents the connection to be disconnected. I would advise the following settings:
# ClientAliveInterval is in seconds
ClientAliveInterval 3600
ClientAliveCountMax 0
This will close the connection after 1 hour if idle.
Solution 2
I had the same requirement and the SSHd ClientAlive* options did not work for me.
I think those are meant to keep the connection alive as opposed to cause when it times out. This means that it relies on the networking equipment timing out idle connection which is not always the case.
If you are running bash/ksh/zsh, you can use the TMOUT environment variable:
TMOUT=3600
This will time out your connection after 60 minutes.
For plain sh, you should be able to use:
TIMEOUT=3600
More info: http://www.cyberciti.biz/faq/howto-configure-shell-logout-user-automatically/
Related videos on Youtube
Comments
-
AMIT over 1 year
I have requirement where I want my ssh seesion to target will logout after one hour,but currently leaving an ssh session to target board idle does not get auto logout after one hour.
Below is what is set in tagets sshd_config file
ClientAliveInterval 15 ClientAliveCountMax 4
So what changes I need to do so that my ssh session gets logged out after hour if it remains idle.
-
Martin Prikryl about 3 yearsThis does not work anymore as of OpenSSH 8.2. See Configure OpenSSH to disconnect idle SFTP clients.