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 / 问题 / 538897
Accepted
John Crawford
John Crawford
Asked: 2013-09-15 01:13:26 +0800 CST2013-09-15 01:13:26 +0800 CST 2013-09-15 01:13:26 +0800 CST

SSH 中的 ServerAliveCountMax

  • 772

SSH 中的 ServerAliveCountMax 实际上是做什么的?

我试图确保当我通过 SSH 连接到我的服务器时,连接会在很长一段时间内保持打开状态,而不是在短时间不活动后连接断开。这是示例

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 2

我从一个消息来源获悉,只要服务器收到该响应,上述设置将始终每 60 秒向服务器发送一次响应。但是,如果由于某种原因响应没有通过服务器,它将尝试发送另一条消息。如果该消息也失败,那么它将关闭连接。(我觉得这是错误的)

然而,第二个和第三个消息来源说的有些不同。他们声称如果有一段时间不活动,将每 60 秒向服务器发送一条消息,但它只会通过 2 个请求发送,然后它将关闭连接。

那么 ServerAliveCountMax 到底是做什么的呢?

ssh
  • 2 2 个回答
  • 44549 Views

2 个回答

  • Voted
  1. Best Answer
    Michael Hampton
    2013-09-15T03:39:22+08:002013-09-15T03:39:22+08:00

    您认为“这是错误的”是正确的。请参阅手册页:

     ServerAliveCountMax
             Sets the number of server alive messages (see below) which may be
             sent without ssh(1) receiving any messages back from the server.
             If this threshold is reached while server alive messages are
             being sent, ssh will disconnect from the server, terminating the
             session.  It is important to note that the use of server alive
             messages is very different from TCPKeepAlive (below).  The server
             alive messages are sent through the encrypted channel and there‐
             fore will not be spoofable.  The TCP keepalive option enabled by
             TCPKeepAlive is spoofable.  The server alive mechanism is valu‐
             able when the client or server depend on knowing when a connec‐
             tion has become inactive.
    
             The default value is 3.  If, for example, ServerAliveInterval
             (see below) is set to 15 and ServerAliveCountMax is left at the
             default, if the server becomes unresponsive, ssh will disconnect
             after approximately 45 seconds.  This option applies to protocol
             version 2 only.
    
     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.  This option applies to protocol version 2 only.
    
    • 47
  2. Drew Chapin
    2018-08-19T17:45:50+08:002018-08-19T17:45:50+08:00

    当 SSH 服务器被配置为在一段时间没有流量后关闭连接时,服务器活动消息很有用(例如,提供 SSH 访问的共享 Web 托管提供商几乎总是这样做)。设置这两个选项每秒钟发送一个数据包ServerAliveInterval,最多发送一次,ServerAliveCountMax从而使会话保持活动状态。

    为了回答有关将任一选项设置为不确定性的评论0,我已经阅读了openssh实现的源代码,这就是我所看到的......

    • 设置ServerAliveInterval为0不会发送数据包,但它会无限期地保持会话活动,假设连接没有由于 TCP 超时而被丢弃并且服务器没有配置为丢弃不活动的客户端。

    • 设置为与设置ServerAliveCountMax为0具有相同的效果。ServerAliveInterval0

    • 将任一值设置为负数或大于INT_MAX(即 2,147,483,647)将导致“整数值...”错误。

    • 在(ie 2,147,484) 到(ie 2,147,483,647)ServerAliveCountMax之间 设置也相当于将任一值设置为。INT_MAX/1000+1INT_MAX0

    因此,从本质上讲,您可以获得的最多超时(同时仍在发送数据包)是INT_MAX/1000(即 2,147,483)。如果会话超时1且完全没有流量,那将让您有将近 25 天的时间。

    显然,SSH 的其他实现可能会有不同的结果。

    • 20

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

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