Chinaunix首页 | 论坛 | 博客
  • 博客访问: 321407
  • 博文数量: 120
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 1290
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-19 01:46
文章分类

全部博文(120)

文章存档

2010年(84)

2009年(36)

我的朋友

分类:

2010-04-06 16:59:24

当用SSH Secure Shell连接Linux时,如果几分钟没有任何操作,连接就会断开。必须重新登陆才行,每次都重复相同的操作,很是烦人,一般修改两个地方可将这烦人的问题解决

 

1echo $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 0ClientAliveCountMax 3的注释符号去掉,ClientAliveInterval对应的0改成60,ClientAliveInterval指定了服务器端向客户端请求消息 的时间间隔, 默认是0, 不发送.ClientAliveInterval 60表示每分钟发送一次, 然后客户端响应, 这样就保持长连接了.这里比较怪的地方是:不是客户端主动发起保持连接的请求(FTerm, CTerm),而是需要服务器先主动.

ClientAliveCountMax, 使用默认值3即可.ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值, 就自动断开. 正常情况下, 客户端不会不响应.

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

 

下面是man sshd_config获取的描述信息

 ClientAliveInterval
             Sets a timeout interval in seconds after which if no data has
             been received from the client, sshd will send a message through
             the encrypted channel to request a response from the client.
             The default is 0, indicating that these messages will not be
             sent to the client.  This option applies to protocol version 2
             only.

 

    

 ClientAliveCountMax
             Sets the number of client alive messages (see above) which may
             be sent without sshd receiving any messages back from the
             client.  If this threshold is reached while client alive mes-
             sages are being sent, sshd will disconnect the client, terminat-
             ing the session.  It is important to note that the use of client
             alive messages is very different from TCPKeepAlive (below).  The
             client alive messages are sent through the encrypted channel and
             therefore will not be spoofable.  The TCP keepalive option
             enabled by TCPKeepAlive is spoofable.  The client alive mecha-
             nism is valuable when the client or server depend on knowing
             when a connection has become inactive.

             The default value is 3.  If ClientAliveInterval (above) is set
             to 15, and ClientAliveCountMax is left at the default, unrespon-
             sive ssh clients will be disconnected after approximately 45
             seconds.

3. 启用putty keepalive
putty -> Connection -> Seconds between keepalives ( 0 to turn off ),
默认为0, 改为60.

  1. 上述3个方法应该能解决大部分问题, 如果不行, man sshd_config, 然后尝试更改其他设置吧.

=========================================================================

方法1:更改ssh服务器的配置文件/etc/ssh/sshd_config

ClientAliveInterval指定了服务器端向客户端请求消息的时间间隔, 默认是0,不发送。而ClientAliveInterval 60表示每分钟发送一次,然后客户端响应,这样就保持长连接了。这里比较怪的地方是:不是客户端主动发起保持连接的请求(FTerm, CTerm),而是需要服务器先主动。

另外,至于ClientAliveCountMax,使用默认值3即可。ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值,就自动断开,正常情况下,客户端不会不响应。

ClientAliveCountMax

Sets the number of client alive messages (see below) which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the ses-sion. It is important to note that the use of client alive messages is very different from TCPKeepAlive (below). The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.The default value is 3. If ClientAliveInterval (see below) is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. This option applies to protocol version 2 only.

ClientAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

vim /etc/ssh/sshd_config

找到ClientAliveInterval 参数,如果没有就自己加一行。

ClientAliveInterval 参数的数值是秒,比如你设置为540,就是9分钟.

ClientAliveInterval 540

对于ClientAliveCountMax

指如果发现客户端没有相应,则判断一次超时,这个参数设置允许超时的次数,比如10

ClientAliveInterval 540

ClientAliveCountMax 10;

则代表允许超时 5400= 90分钟。

方法2:配置客户端

1 linux下的ssh命令

vim /etc/ssh/ssh_config

然后找到里面的ServerAliveInterval 参数,如果没有你同样自己加一个就好了。参数意义相同,都是秒数,比如9分钟:

ServerAliveInterval 540

2 SecureCRT

设置反空闲,如下图所示

ssh超时断开的解决方法

3 Putty

启用putty keepalive

putty -> Connection -> Seconds between keepalives ( 0 to turn off ),默认为0,改为60




阅读(1746) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~