時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(0)
當用SSH Secure Shell連接Linux時,如果幾分鐘沒有任何操作,連接就會斷開,必須重新登陸才行,每次都重復相同的操作,很是煩人,本文總結(jié)了兩種解決的方法。
方法1:更改ssh服務(wù)器的配置文件/etc/ssh/sshd_config
ClientAliveInterval指定了服務(wù)器端向客戶端請求消息的時間間隔, 默認是0,不發(fā)送。而ClientAliveInterval 60表示每分鐘發(fā)送一次,然后客戶端響應,這樣就保持長連接了。這里比較怪的地方是:不是客戶端主動發(fā)起保持連接的請求(如FTerm, CTerm等),而是需要服務(wù)器先主動。
另外,至于ClientAliveCountMax,使用默認值3即可。ClientAliveCountMax表示服務(wù)器發(fā)出請求后客戶端沒有響應的次數(shù)達到一定值,就自動斷開,正常情況下,客戶端不會不響應。
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 參數(shù),如果沒有就自己加一行。
ClientAliveInterval 參數(shù)的數(shù)值是秒,比如你設(shè)置為540,就是9分鐘.
ClientAliveInterval 540
對于ClientAliveCountMax
指如果發(fā)現(xiàn)客戶端沒有相應,則判斷一次超時,這個參數(shù)設(shè)置允許超時的次數(shù),比如10。
ClientAliveInterval 540
ClientAliveCountMax 10;
則代表允許超時 5400秒 = 90分鐘。
方法2:配置客戶端
1 linux下的ssh命令
vim /etc/ssh/ssh_config
然后找到里面的ServerAliveInterval 參數(shù),如果沒有你同樣自己加一個就好了。參數(shù)意義相同,都是秒數(shù),比如9分鐘:
ServerAliveInterval 540
設(shè)置反空閑,如下圖所示
3 Putty
啟用putty keepalive
putty -> Connection -> Seconds between keepalives ( 0 to turn off ),默認為0,改為60。
關(guān)鍵詞標簽:ssh超時,解決方法
相關(guān)閱讀
熱門文章 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 Tomcat9.0如何安裝_Tomcat9.0環(huán)境變量配置方法 多種操作系統(tǒng)NTP客戶端配置 Linux操作系統(tǒng)修改IP
人氣排行 Linux下獲取CPUID、硬盤序列號與MAC地址 dmidecode命令查看內(nèi)存型號 linux tc實現(xiàn)ip流量限制 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 linux下解壓rar文件 lcx.exe、nc.exe、sc.exe入侵中的使用方法 Ubuntu linux 關(guān)機、重啟、注銷 命令 查看linux服務(wù)器硬盤IO讀寫負載