ssh超時斷開的解決方法

當用SSH Secure Shell鏈接Linux時,若是幾分鐘沒有任何操做,鏈接就會斷開,必須從新登錄才行,每次都重複相同的操做,非常煩人,本文總結了兩種解決的方法。linux

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

ClientAliveInterval指定了服務器端向客戶端請求消息的時間間隔, 默認是0,不發送。而ClientAliveInterval 60表示每分鐘發送一次,而後客戶端響應,這樣就保持長鏈接了。這裏比較怪的地方是:不是客戶端主動發起保持鏈接的請求(如FTerm, CTerm等),而是須要服務器先主動。服務器

另外,至於ClientAliveCountMax,使用默認值3便可。ClientAliveCountMax表示服務器發出請求後客戶端沒有響應的次數達到必定值,就自動斷開,正常狀況下,客戶端不會不響應。app

 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_configssh

找到ClientAliveInterval 參數,若是沒有就本身加一行。this

ClientAliveInterval 參數的數值是秒,好比你設置爲540,就是9分鐘.lua

ClientAliveInterval 540spa

對於ClientAliveCountMaxcode

指若是發現客戶端沒有相應,則判斷一次超時,這個參數設置容許超時的次數,好比10。server

ClientAliveInterval 540

ClientAliveCountMax 10;

則表明容許超時 5400秒 = 90分鐘。

方法2:配置客戶端

1. linux下的ssh命令

vim /etc/ssh/ssh_config

而後找到裏面的ServerAliveInterval 參數,若是沒有你一樣本身加一個就行了。參數意義相同,都是秒數,好比9分鐘:

ServerAliveInterval 540

2. SecureCRT

設置反空閒,以下圖所示

securecrt_to

 

3 Putty

 

啓用putty keepalive

 

putty -> Connection -> Seconds between keepalives ( 0 to turn off ),默認爲0,改成60。

相關文章
相關標籤/搜索