Ask Your Question

Setting up a time out in ssh

asked 2019-03-01 12:35:10 -0600

evansmb gravatar image

I'm trying to setup a idle time out on ssh. Looking through the net it looks like I really just need to set three options and restart the server, I've done this, it still isn't closing connections. Any one have any thoughts on this?

TCPKeepAlive yes
ClientAliveInterval 300
ClientAliveCountMax 4

edit retag flag offensive close merge delete


These configuration lines keeps the network connection alive so the various firewalls and routers don't close the connection.

villykruse gravatar imagevillykruse ( 2019-03-02 01:10:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-03-10 10:24:32 -0600

updated 2019-03-11 03:02:28 -0600

You can set the time settings for automatic logout in your ssh configuration. Please remove ' # ' from the following settings in /etc/ssh/sshd_config

A. User file change for Force logout 5Minutes(300Seconds)- Simple and Fast use....!!

 # /home/user/.bashrc [user]  or /etc/profile [all]
 TMOUT=300                    or export TMOUT=300

 $ Connection to mas closed by remote host.
 Connection to mas closed.

B. Login

   #LoginGraceTime 2m  ->  LoginGraceTime 2m

C. Time out in no response adjust value for you. [10Minutes]

    # ClientAliveInterval 0        -> ClientAliveInterval 600
    # ClientAliveCountMax 3    -> ClientAliveCountMax 1

You can adjust the time by changing the constant value of the set value. It is based on the minute setting value. If you do not change the value, you will be automatically logged out after 2 minutes.

Just use in case login @ villykruse comment's conider for login....

# man sshd_config|grep LoginGraceTime
  until authentication succeeds or the LoginGraceTime expires for a connection.  The default is 10:30:100.

# man sshd_config|grep ClientAliveInterval
  The default value is 3.  If ClientAliveInterval is set to 15, and ClientAliveCountMax is left at the default, 
  unresponsive SSH  ClientAliveInterval AuthorizedPrincipalsFile, Banner, ChrootDirectory, lientAliveCountMax, 
  ClientAliveInterval, DenyGroups, DenyUsers, ForceCommand,
edit flag offensive delete link more



From man sshd_configL

         The server disconnects after this time if the user has not successfully logged in.  If the value is
         0, there is no time limit.  The default is 120 seconds.
villykruse gravatar imagevillykruse ( 2019-03-10 12:32:35 -0600 )edit

Thanks and check commet^^

simmon gravatar imagesimmon ( 2019-03-10 13:06:07 -0600 )edit

Question Tools

1 follower


Asked: 2019-03-01 12:35:10 -0600

Seen: 78 times

Last updated: Mar 11 '19