天天看點

如何避免SSH Secure Shell Client連接配接Linux逾時,自動斷開?

很多新手在使用SSH

Secure Shell Client的過程中,肯定經常會遇到當用SSH Secure

Shell連接配接Linux時,如果幾分鐘沒有任何操作,連接配接就會斷開,提示server responded "connection closed"

。必須重新登陸才行,每次都重複相同的操作,很是煩人。

一般修改兩個地方可将這煩人的問題解決

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、修改/etc/ssh/sshd_config檔案,将 ClientAliveInterval

0和ClientAliveCountMax

3的注釋符号去掉,将ClientAliveInterval對應的0改成60,ClientAliveInterval指定了伺服器端向用戶端請求消息

的時間間隔, 預設是0, 不發送.而ClientAliveInterval 60表示每分鐘發送一次, 然後用戶端響應,

這樣就保持長連接配接了.ClientAliveCountMax,

使用預設值3即可.ClientAliveCountMax表示伺服器送出請求後用戶端沒有響應的次數達到一定值, 就自動斷開. 正常情況下,

用戶端不會不響應.

最後記得執行/etc/init.d/sshd restart 哦,否則剛才的修改是不會生效的。

注意:要斷開連結,重新登入後,才會生效

想參考更多,請輸入man sshd_config了解更多資訊