链接断开时autossh不会杀死ssh


10

我的autossh witt开始了30秒的轮询时间:

AUTOSSH_POLL=30 AUTOSSH_LOGLEVEL=7 autossh -M 0 -f -S none -f -N -L localhost:34567:localhost:6543 user1@server1

它工作正常:

Sep  5 12:26:44 serverA autossh[20935]: check on child 23084
Sep  5 12:26:44 serverA autossh[20935]: set alarm for 30 secs

但是,如果我物理上拔下了网络电缆,这意味着隧道无法再使用,则autossh不会终止ssh守护程序。为什么?我知道如果链接断开,autossh不能执行任何操作,但是我认为它应该尝试执行以下操作:

  1. 验证子ssh进程(check on child ...
  2. 验证远端!!!(通过隧道执行的类似ping的操作)
  3. 意识到隧道已关闭
  4. 停止ssh进程
  5. 尝试再次创建隧道
  6. 意识到它不起作用,并设置了(呈指数增长?)计时器以很快再次检查

这就是为什么我运行autossh的原因:如果隧道发生了任何事情(无论是软件还是硬件问题),它都应尝试重新启动它。相反,它只是在等待ssh进程终止。即使没有希望重新建立连接,它也不应该尝试重新启动它吗?

autossh正在执行哪种检查?只需验证ssh是否已启动并正在运行?它不执行任何远端检查吗?

编辑

根据要求,我添加了ssh配置的相关部分:

# (see http://aaroncrane.co.uk/2008/04/ssh_faster)
# The ServerAliveInterval tells SSH to send a keepalive message every 60 seconds while the connection is open;
#   that both helps poor-quality NAT routers understand that the NAT table entry for your connection should
#   be kept alive, and helps SSH detect when there’s a network problem between the server and client.
ServerAliveInterval 60
# The ServerAliveCountMax says that after 60 consecutive unanswered keepalive messages, the connection should
#   be dropped. At that point, AutoSSH should try to invoke a fresh SSH client. You can tweak those
#   specific values if you want, but they seem to work well for me.
ServerAliveCountMax 60

TCPKeepAlive yes

如何减少超时时间呢?
Nikolaidis Fotis 2014年

我们使用autossh已有一段时间,但是在不稳定的连接上,尤其是在与端口转发结合使用时,它太不可靠了。我们现在使用OpenVPN,对此非常满意。
Nils Toedtmann 2014年

@NikolaidisFotis:超时很好。现在...超时。但是,只要超时到来,它就不会做正确的事情(恕我直言),即:验证远端
dangonfast 2014年

@NilsToedtmann:谢谢,我试试看。容易实现吗?您是否有任何指向好的指导的链接?
dangonfast 2014年

OpenVPN非常简单,我们只需对其进行“ apt-get install”安装,并开始使用服务器或客户端的默认配置dev tun,两者都使用,并remote在客户端配置中进行设置即可。唯一令人讨厌的地方是管理证书。我们使用OpenVPN随附的“ easy-rsa” CA。获得证书后,其余的工作就很容易了。
Nils Toedtmann 2014年

Answers:


11

但是,如果我物理上拔下了网络电缆,这意味着隧道无法再使用,则autossh不会终止ssh守护程序。为什么?

autossh在您的客户端计算机上运行,​​因此它无法直接终止服务器上的ssh守护进程。但是,您可以在服务器上为ClientAliveIntervalin 指定一个非零值/etc/ssh/sshd_config(请参阅man sshd_config参考资料),然后在服务器上重新启动sshd服务以应用配置更改。然后,如果网络断开连接,ssh守护进程将在ClientAliveInterval * ClientAliveCountMax几秒钟后被杀死(但不会被autossh 杀死)。

现在,如果您想问“为什么不使用autossh杀死ssh客户端进程?” ,您已指定-M 0。在autossh手册页中:

Setting the monitor port to 0 turns the monitoring function off, and autossh will only restart ssh upon ssh's exit

而不是使用autossh监视连接,而是等待ssh在ServerAliveCountInterval * ServerAliveCountMax几秒钟的超时后退出。在ssh退出之前,您已请求60项服务器活动检查,并且间隔60秒的间隔将连续的检查分开,因此您将等待一个小时,直到ssh客户端退出。

您也可以考虑ExitOnForwardFailure在客户端使用该选项(请参阅man ssh_config参考资料),以便ssh在无法建立隧道的情况下退出,然后autossh可以尝试再次启动ssh。


谢谢,这很有意义。我的意思确实是“客户端进程”,而不是服务器进程。
dangonfast 2014年

现在,在重新阅读autossh手册页之后,我记得我设置的原因-M 0:使用监视端口并不容易,并且间接建议不
要这样做
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.