解决ssh无操作自动断开[转载,已经验证]

用SSH远程,如果几分钟没有任何操作,连接就会断开,必须重新登陆才行,非常麻烦,一般修改2个地方3项即可解决问题:

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文件(要sudo),将ClientAliveInterval 0和ClientAliveCountMax 3的注释符号去掉,然后将ClientAliveInterval的值0改成60,
ClientAliveCountMax的值3改成10000。ClientAliveInterval指定了服务器端向客户端请求消息的时间间隔,默认是0,不发送。而ClientAliveInterval 60表示每分钟发送一次,然后客户端响应,这样就保持长连接了。ClientAliveCountMax,使用默认值3即可,ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值,就自动断开,设成10000或更大,保证不断开(

posted @ 2014-09-23 14:23  jamesbd  阅读(627)  评论(0编辑  收藏  举报