1. 程式人生 > >putty超時解決方案

putty超時解決方案

putty連續3分鐘左右沒有輸入, 就自動斷開, 然後必須重新登陸, 很麻煩.

在網上查了很多資料, 發現原因有多種, 環境變數TMOUT引起,ClientAliveCountMax和ClientAliveInterval設定問題或者甚至是防火牆的設定問題. 所以可以這麼嘗試:

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. ClientAliveInterval 60
在/etc/ssh/sshd_config中增加ClientAliveInterval 60, 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 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 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 45seconds. 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.

3. 啟用putty keepalive
putty -> Connection -> Seconds between keepalives ( 0 to turn off ), 預設為0, 改為60.

4. 上述3個方法應該能解決大部分問題, 如果不行, 請 man sshd_config, 然後嘗試更改其他設定吧.