vi /etc/ssh/sshd_config

找到选项

#ClientAliveInterval 0

修改为

ClientAliveInterval 1800

重启sshd 服务

service sshd restart

这样,超过1800秒(半个小时)没有动作的情况下,sshd服务才会中断连接。

***************************************************************************

网上很多文章都说,远程SSH连接的超时设定是在/etc/ssh/sshd_config里,使用ClientAliveInterval和ClientAliveCountMax选项,我原来也这么认为的,不过一直没配置过超时。

 
今天配置了一下,发现这个是不对的,正确的配置是在/etc/profile里,使用TMOUT选项进行控制,如TMOUT=300,设定超时间隔为300秒。
系统版本(CentOS-6.4 64位)最佳配置10分钟:
TMOUT=600
******************************************************************
很多新手在使用SSH Secure Shell Client的过程中,肯定经常会遇到当用SSH Secure Shell连接Linux时,如果几分钟没有任何操作,连接就会断开,提示server responded "connection closed" 。必须重新登陆才行,每次都重复相同的操作,很是烦人。

一般修改两个地方可将这烦人的问题解决

1、echo $TMOUT

如果显示空白,表示没有设置, 等于使用默认值0, 一般情况下应该是不超时. 如果大于0, 可以在如/etc/profile之类文件中设置它为0.

Definition: TMOUT: If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if input does not arrive

2、修改/etc/ssh/sshd_config文件,将 ClientAliveInterval 0和ClientAliveCountMax 3的注释符号去掉,将ClientAliveInterval对应的0改成60,ClientAliveInterval指定了服务器端向客户端请求消息 的时间间隔, 默认是0, 不发送.而ClientAliveInterval 60表示每分钟发送一次, 然后客户端响应, 这样就保持长连接了.ClientAliveCountMax, 使用默认值3即可.ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值, 就自动断开. 正常情况下, 客户端不会不响应.

最后记得执行/etc/init.d/sshd restart 哦,否则刚才的修改是不会生效的。

想参考更多,请输入man sshd_config了解更多信息

大家这下明白了吧,是不是现在觉得很爽,在使用SSH Secure Shell Client链接LINUX的时候再也不会超时和自动断开了,也不会再出现烦人的 server responded "connection closed" 错误提示了,很开心吧!

技术分类 | 评论(0) | 引用(0) | 阅读(7279)