歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> ssh設置超時時間

ssh設置超時時間

日期:2017/3/1 17:02:21   编辑:關於Linux
ssh設置超時時間 ssh連接超時問題解決方案: 1.修改server端的etc/ssh/sshd_config ClientAliveInterval 60 #server每隔60秒發送一次請求給client,然後client響應,從而保持連接 www.2cto.com ClientAliveCountMax 3 #server發出請求後,客戶端沒有響應得次數達到3,就自動斷開連接,正常情況下,client不會不響應 2.修改client端的etc/ssh/ssh_config添加以下:(在沒有權限改server配置的情形下) ServerAliveInterval 60 #client每隔60秒發送一次請求給server,然後server響應,從而保持連接 ServerAliveCountMax 3 #client發出請求後,服務器端沒有響應得次數達到3,就自動斷開連接,正常情況下,server不會不響應 www.2cto.com 3.另一種方式: 不修改配置文件 在命令參數裡ssh -o ServerAliveInterval=60 這樣子只會在需要的連接中保持持久連接, 畢竟不是所有連接都要保持持久的 =====================補充======================== keeping your ssh session alive through pesky(討厭的,麻煩的) NAT firewalls. NAT firewalls like to time out idle sessions to keep their state tables clean and their memory footprint low. NAT防火牆喜歡對空閒的會話進行超時處理,以確保它們狀態表的干淨和內存的低占用率。 Some firewalls are nice, and let you idle for up to a day or so; some are gestapo and terminate your session after 5 minutes. 一些防火牆比較友好,允許你的空閒會話時間為一天甚至超過一天;另一些卻如蓋世太保,5分鐘空閒就終止你的會話。 I finally got tired of my ssh sessions getting disconnected at places where I don't control the firewalls, and figured out how to stop it. 我最終疲於我的ssh連接會話被我不能控制的防火牆斷開,並找出了阻止它的方案。 Turn out ssh has a nice inband keepalive mechanism, and even lets you set it on a per-destination basis. 結論是ssh內帶有一個很好的保持會話存活機制,甚至允許你在每一台目標機器上設置。 Just create a ~/.ssh/config file with something like the following (* will match any host, if you wanted you could restrict this to particular destinations like *kehlet.cx): 只要用以下類似的內容創建一個 ~/.ssh/config文件(*號將匹配所有的主機,如果你想,你可以嚴格的設置它為特定的目標主機,像kehlet.cx): ---------------- Host * ServerAliveInterval 240 ---------------- That's how often, in seconds, ssh will send a keepalive request (at the application layer) to the other end if the connection's been otherwise idle. 4 minutes should be good :-). 這通常是以秒為單位,如果這個連接空閒,ssh將發送一個保持存活的請求(在應用層)給另一端。4分鐘應該不錯。 The Host line lets you pattern match your destinations. Minimal effort, no impact to your system (say, as you would have if you mucked with your system's default TCP keepalive settings), and it works like a charm. Host行使你匹配你的目標主機。極小的努力,對你的系統毫無影響(即,如果你弄亂你的系統默認TCP保持存活時間設置的話,將影響你的系統),並且很有效。
Copyright © Linux教程網 All Rights Reserved