当我使用ssh登录远程服务器并打开vim时,如果我没有输入任何单词,会话将超时,我必须再次登录。 但是,如果我像top一样运行命令会话永远不会超时? 是什么原因?
答案 0 :(得分:1)
相比之下,顶部每隔几秒更新一次屏幕,这被视为活动,连接保持打开状态,因为有定期数据流过它。
有些选项可以添加SSH服务器的配置以发送定时的“空”数据包以保持连接活动,即使链接上没有实际的用户数据:http://www.howtogeek.com/howto/linux/keep-your-linux-ssh-session-from-disconnecting/
答案 1 :(得分:1)
请注意,您所看到的行为与vim
或top
无关。机会很好,一路上的路由器正在剔除"死了" TCP会话。这通常由NAT firewall或stateful 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会话超时