使用“vim”可以导致ssh超时,但“top”不会

时间:2012-03-05 02:25:03

标签: ssh

当我使用ssh登录远程服务器并打开vim时,如果我没有输入任何单词,会话将超时,我必须再次登录。 但是,如果我像top一样运行命令会话永远不会超时? 是什么原因?

3 个答案:

答案 0 :(得分:1)

vim只会坐在那里等待输入,并且(除非你的终端屏幕上有时钟或其他东西)也不会产生输出。如果这种情况持续很长时间,大多数防火墙都会将连接视为已死并将其杀死,因为没有活动。

相比之下,顶部每隔几秒更新一次屏幕,这被视为活动,连接保持打开状态,因为有定期数据流过它。

有些选项可以添加SSH服务器的配置以发送定时的“空”数据包以保持连接活动,即使链接上没有实际的用户数据:http://www.howtogeek.com/howto/linux/keep-your-linux-ssh-session-from-disconnecting/

答案 1 :(得分:1)

请注意,您所看到的行为与vimtop无关。机会很好,一路上的路由器正在剔除"死了" TCP会话。这通常由NAT firewallstateful firewall完成,以减少内存压力并防止简单的拒绝服务攻击。

ServerAliveInterval配置选项可能会让您的闲置会话无法获得收益:

 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, or 300 if the BatchMode option is set.  This
         option applies to protocol version 2 only.
         ProtocolKeepAlives and SetupTimeOut are Debian-specific
         compatibility aliases for this option.

尝试将ServerAliveInterval 180添加到~/.ssh/config文件中。这将每三分钟要求一次keepalive探测,这应该比许多防火墙超时更快。

答案 2 :(得分:0)

由于“top”始终通过SSH控制台返回数据,因此它将保持活动状态。

“vim”不会,因为它是静态的,只根据您的按键传输数据。

缺少传输的数据会导致SSH会话超时