2011-05-24

terminal终端下连接ssh时掉线的问题

其实这是因为在ssh的配置文件中没有进行设置,其实修改起来很简单,就是在配置文件(/etc/ssh/ssh_config)中加入以下内容:
TCPKeepAlive yes
ServerAliveInterval 60
其实 TCPKeepAlive yes这这一行可以不要,因为默认的TCPKeepAlive值就是yes

我们可以看一下这些东西是什么意思,在终端中输入
man ssh_config
然后我们可以看到其中有这样的内容

      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.
也有关于TCPKeepAlive的
     TCPKeepAlive
             Specifies whether the system should send TCP keepalive messages
             to the other side.  If they are sent, death of the connection or
             crash of one of the machines will be properly noticed.  However,
             this means that connections will die if the route is down tempo‐
             rarily, and some people find it annoying.

             The default is “yes” (to send TCP keepalive messages), and the
             client will notice if the network goes down or the remote host
             dies.  This is important in scripts, and many users want it too.

             To disable TCP keepalive messages, the value should be set to
             “no”.

本文来自上善若水的博客(blog),欢迎您的访问。

没有评论: