Monday, April 28, 2008

保持SSH客户端不掉线

不管我是使用linux的的SSH还是windows下的putty、SecureCRT还是AbsoluteTelnet,当我连接到服务器端 后,离开一会或者做点其他的事情,再回到SSH的时候,常常发现客户端自动掉出来了;有的时候甚至跑一个需要时间比较长的JOB的时候,还没跑完就掉出来 了,导致JOB跑了一半,等等。。

所以一直在找解决这个问题的办法,今天在googleReader上找到了一个解决办法,如下:

Do you get annoyed when you have a SSH session open, visit your browser for a while, and then return only to find you were disconnected? Most home NAT routers are the cause of this. If your router doesn't offer an option to not shut off idle connections, you are probably better off by setting a keep-alive setting.

To do this, just open /etc/ssh/ssh_config on your home (client) computer. Add the following line:

 

配置代码
  1. ServerAliveInterval 180  
There you have it! Just remember now, if you leave SSH open accidentally, anyone else can get on it. Remember to close your session when finished.PS:If you're using AbsoluteTelnet (for Windows), you can do this from the Options->Properties->Connection page. There is an option there to enable keepalives and you can specify the duration between them.
 

No comments: