AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 626461
Accepted
blueFast
blueFast
Asked: 2014-09-06 02:41:31 +0800 CST2014-09-06 02:41:31 +0800 CST 2014-09-06 02:41:31 +0800 CST

链接断开时,autossh 不会终止 ssh

  • 772

我已经开始了我的 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
networking
  • 1 1 个回答
  • 13628 Views

1 个回答

  • Voted
  1. Best Answer
    James W
    2014-10-06T19:44:07+08:002014-10-06T19:44:07+08:00

    但是如果我物理移除了网络电缆,这意味着隧道不能再工作了,autossh 不会杀死 ssh 守护进程。为什么?

    autossh 在您的客户端计算机上运行,​​因此它不能直接杀死服务器上的 ssh 守护进程。ClientAliveInterval但是,您可以在服务器上为in指定一个非零值/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 次 server-alive 检查,连续检查间隔为 60 秒,因此您将在 ssh 客户端退出之前等待一个小时。

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

    • 20

相关问题

  • 谁能指出我的 802.11n 范围扩展器?

  • 我怎样才能得到一个网站的IP地址?

  • 在一个 LAN 中使用两台 DHCP 服务器

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve