链接closures时,autossh不会终止ssh

我已经开始了我的autossh 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 

但是,如果我物理删除networking电缆,意味着隧道不能再工作,autossh不杀死SSH守护进程。 为什么? 我明白,autossh不能做任何事情,如果链接closures,但在我看来,它应该尝试做到以下几点:

  1. validation孩子的ssh过程( check on child ...
  2. validation远端! (通过隧道的ping式操作)
  3. 意识到隧道已经closures了
  4. 停止ssh进程
  5. 尝试再次创build隧道
  6. 意识到它不工作,并build立一个(指数增长?)计时器,以再次检查

这就是为什么我正在运行autossh:如果隧道出现问题(无论是软件还是硬件问题),它应该尝试重新启动它。 相反,它只是在等待ssh进程死掉。 不应该试图重新启动它,即使没有重build连接的希望吗?

什么样的检查正在做autossh? 只需确认ssh已启动并正在运行? 这是不是做了任何远端检查?

编辑

按照要求,我添加了ssh config的相关部分:

 # (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 

但是,如果我物理删除networking电缆,意味着隧道不能再工作,autossh不杀死SSH守护进程。 为什么?

autossh在你的客户端机器上运行,所以它不能直接杀死服务器上的ssh守护进程。 但是,可以在服务器上的/etc/ssh/sshd_configClientAliveInterval指定一个非零值(请参阅man sshd_config ),然后重新启动服务器上的sshd服务以应用configuration更改。 然后,在networking断开的情况下,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 ),以便在无法build立隧道的情况下ssh将退出,然后autossh可以尝试再次启动ssh。