知道一个技巧来维持从防火墙自动断开连接的安静的SSH连接?

我们的企业防火墙configuration为在30分钟不活动之后断开ssh连接。 有时候,我需要在超过这段时间的持续连接的服务器上执行一个操作,但是我的shell看起来是不活动的(至less在防火墙上)。

看起来,打开第二个连续活动的ssh连接(比如跑顶)不足以维持shell。 我不希望将stream程设置为背景,然后将前景设置为更具互动性,因为任何警报或警告都可能会引起我的注意。 我可以周期性地每隔x分钟重复敲击shell窗口中的返回键,但这是不可取的。

有些程序,像sweep(来自Sophos)有一个在shell中旋转的光标,维持连接(也就是说,循环遍历\ / / – 等等)。 这很好。

是否有一些诀窍,可能与bash相关,可以达到这个目的?

在您的客户端的.ssh / config中,尝试添加这样的内容。

Host * ServerAliveInterval 60 

男人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... 

从腻子中,您可能希望将Connection\Seconds between keepalivesConnection\Seconds between keepalives调整为非零值。

如果在screen会话中运行,您可以将“系统负载”计数器添加到屏幕的底部(或系统date/时间 – caption always "%d.%m.%y %0c%{=b kW}"添加类似caption always "%d.%m.%y %0c%{=b kW}"你的.screenrc可以做到这一点),这将不定期产生一些小输出(重画负载号码或date/时间)。

这是它的样子 – 左下angular,系统负载

这是它的样子 - 左下角,系统负载

一个更不直的:)解决scheme(keepalives是最直接的)将是有一些shell脚本在后台运行,并产生一些输出到stderr每30-60秒…例如while true; do echo "ding" > /dev/stderr; sleep 30; done & while true; do echo "ding" > /dev/stderr; sleep 30; done & while true; do echo "ding" > /dev/stderr; sleep 30; done &