ssh - sshd_config 中 maxstartups 和 maxsessions 的区别

标签 ssh server config

我想限制 ssh 连接的总数。我已经阅读了许多 sshd 手册。他们只是说这两个字段可以使用
MaxStartups:到 SSH 守护进程的最大并发未经身份验证连接数
MaxSession:每个 TCP 连接允许的(多路复用)打开 session 的最大数量。
两者在计算 ssh 连接总数方面的贡献是什么?

最佳答案

这个问题已经很老了,可能更适合 serverfault,但除了引用手册页之外,它从未得到答案。我的回答是通过添加一些上下文来补充手册页的细节。
首先,应该注意的是,这两个设置是相互独立的,它们针对 SSH 连接的不同阶段。
最大 session 数
SSH 允许 session 多路复用,即仅使用一个 TCP 连接同时打开多个 session (例如 shell、sftp 传输和原始命令)。这节省了多次 TCP 握手和多次 SSH 身份验证的开销。参数MaxSessions允许将此多路复用限制为一定数量的 session 。
如果您设置 MaxSessions 1并打开一个 shell ,您仍然可以运行 SFTP 传输或打开第二个 shell ,但在后台 SSH 将打开另一个 TCP 连接并再次进行身份验证。 (使用密码身份验证使其可见)。
如果您设置 MaxSessions 0您可以确保没有人可以打开 session (shell、SFTP 或类似的),但您仍然可以连接以打开隧道或 ssh 进入下一个主机。
查看 ssh_config(5) 的 ControlMaster 部分.

MaxSessions
     Specifies the maximum number of open shell, login or subsystem
     (e.g. sftp) sessions permitted per network connection.  Multiple
     sessions may be established by clients that support connection
     multiplexing.  Setting MaxSessions to 1 will effectively disable
     session multiplexing, whereas setting it to 0 will prevent all
     shell, login and subsystem sessions while still permitting for-
     warding.  The default is 10.
MaxStartups
当您连接到远程 SSH 服务器时,在建立连接和成功验证之间有一个时间窗口。这个时间范围可以非常小,例如当您将 SSH 客户端配置为为此连接使用某个私钥时,或者它可能很长时,当客户端首先尝试三个不同的 SSH key 时,要求您输入密码,然后等待您输入第二因素身份验证代码你通过短信收到。同时在此时间范围内的连接总数是引用的手册页中提到的“并发未经身份验证的连接”。如果处于这种状态的连接过多,sshd 将停止接受新的连接。您可以调整 MaxStartups发生这种情况时进行更改。
例如,更改默认值的真实用例是由 ansible 等配置软件使用的跳转主机。当要求在跳转主机后面配置大量主机时,Ansible 会同时打开许多连接,因此如果打开连接的速度比 SSH 主机能够对其进行身份验证的速度快,它可能会遇到此限制。
MaxStartups
     Specifies the maximum number of **concurrent   unauthenticated con-
     nections to the SSH daemon.**  Additional connections will be
     dropped until authentication succeeds or the LoginGraceTime
     expires for a connection.  The default is 10:30:100.

     Alternatively, random early drop can be enabled by specifying the
     three colon separated values ``start:rate:full'' (e.g.
     "10:30:60").  sshd(8) will refuse connection attempts with a
     probability of ``rate/100'' (30%) if there are currently
     ``start'' (10) unauthenticated connections.  The probability
     increases linearly and all connection attempts are refused if the
     number of unauthenticated connections reaches ``full'' (60).

关于ssh - sshd_config 中 maxstartups 和 maxsessions 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31114690/

相关文章:

ubuntu - 作为 systemctl start SERVICE 运行的 Autossh 脚本有效,但 systemctl enable SERVICE 失败

php - 如何将 SSH 隧道反向到 Xdebug 的远程 docker 容器?

python - fabric 一直要求输入密码

redirect - DNS 记录将 www 重定向到非 www

MySQL 5.7 复制

java - 这是为我的 servlet 添加 "global"参数的正确方法吗?

javascript - 用于生产和非生产环境的 Segment.io 和 mixpanel 实现配置文件?

php - Apache 用户帐户无密码访问服务器 - Ubuntu

php - 错误 :error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

Python+解析自定义配置文件