問題現象:
表示連接管道已經斷開
解決方法:
方法一:客戶端配置
在客戶端的 ~/.ssh/ config文件(如不存在請自行創建)中添加下面內容:
ServerAliveInterval 60
方法二:服務器端配置
在服務器的 /etc/ssh/sshd_config 中添加如下的配置:
ClientAliveInterval 60
方法三:臨時SSH命令配置
如果只是臨時性的連接(即只作用於當前SSH),可以直接使用 ssh 命令參數進行配置。
$ ssh -o ServerAliveInterval=60 user@sshserver
//ServerAliveInterval Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server. 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.
這兩個命令前者應用在客戶機上,后者應用在服務器上,如果沒有管理員權限,那么前者是很好的選擇。
這兩個的功能是相同的,都是開啟一個發送keep-alive包的功能,這樣會允許客戶端/服務器在一定時間內發送一個特定的包給對方,一旦超時,則說明斷線,就關閉鏈接。這樣就避免了鏈接長時間掛着導致報錯。而且,一旦再次報錯,稍等片刻便可以再次登錄。