[SSH]putty超时解决方案[转载]

heyw 2010-12-18

ssh 超时(ssh timeout) 解决办法

转载自:yaozer博客来的ssh是不会超时的, 但是自从上次给ubuntu Server 系统升级后, 出现了ssh 超时现象:只要putty连续3分钟左右没有输入, 就自动断开, 然后必须重新登陆, 很麻烦.

在网上查了很多资料, 发现原因有多种, 环境变量TMOUT引起,ClientAliveCountMax和ClientAliveInterval设置问题或者甚至是防火墙的设置问题. 所以可以这么尝试:

1, echo $TMOUT

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

Definition:TMOUT:Ifsettoavaluegreaterthanzero,thevalueisinterpretedasthenumberofsecondstowaitforinputafterissuingtheprimaryprompt.Bashterminatesafterwaitingforthatnumberofsecondsifinputdoesnotarrive.

2.ClientAliveInterval60

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

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

ClientAliveCountMax

Setsthenumberofclientalivemessages(seebelow)whichmaybe

sentwithoutsshd(8)receivinganymessagesbackfromtheclient.

Ifthisthresholdisreachedwhileclientalivemessagesare

beingsent,sshdwilldisconnecttheclient,terminatingtheses-

sion.Itisimportanttonotethattheuseofclientalivemes-

sagesisverydifferentfromTCPKeepAlive(below).Theclient

alivemessagesaresentthroughtheencryptedchannelandthere-

forewillnotbespoofable.TheTCPkeepaliveoptionenabledby

TCPKeepAliveisspoofable.Theclientalivemechanismisvalu-

ablewhentheclientorserverdependonknowingwhenaconnec-

tion has become inactive.

The default value is 3. If ClientAliveInterval (see below) is

setto15,andClientAliveCountMaxisleftatthedefault,unre-

sponsiveSSHclientswillbedisconnectedafterapproximately45

seconds. This option applies to protocol version 2 only.

ClientAliveInterval

Setsatimeoutintervalinsecondsafterwhichifnodatahas

beenreceivedfromtheclient,sshd(8)willsendamessage

throughtheencryptedchanneltorequestaresponsefromthe

client.Thedefaultis0,indicatingthatthesemessageswill

notbesenttotheclient.Thisoptionappliestoprotocolver-

sion 2 only.

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

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

相关推荐