html tool

2023年7月10日星期一

转:ssh并发连接控制

 参考:

https://blog.tankywoo.com/2020/09/02/ssh-maxstartups.html

https://juejin.cn/s/sshd_config%20maxstartups%20maxsessions


单个客户端ssh数量

maxsessions用于限制每个客户端可以同时打开的SSH会话数量。这个参数可以防止单个客户端占用过多的服务器资源。maxsessions的语法如下:

typescript
复制代码
MaxSessions number



MaxStartups

past MaxStartups,查阅 man 手册:

MaxStartups
    Specifies the maximum number of concurrent unauthenticated connections 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).

即控制并发初始化连接的个数,初始化连接即还未到认证层面的连接,如默认的 10:30:100,表示如果超过 10 个并发初始化连接,则后续的连接由 30% 的几率直接被关闭,如果超过 100 个连接,则所有新的连接 100% 直接关闭。

再比如我本地模拟测试,配置 MaxStartups 3:100:3,即表示并发初始化连接超过 3 个时,直接 100% 丢包,所以我开 tmux 四个窗口同时登陆服务端,总会有一个连接报错并关闭连接。

结合实际的场景为何会出现这个问题,我们的服务器都做了 ssh 白名单防火墙限制,只有白名单的网段可以登录,其余数据包在防火墙层面直接丢弃;但是个别服务器因为一些原因,未开启此配置,导致有大量的 ssh 端口扫描,自然就达到了 MaxStartups 的限制,也就出现了偶尔丢包的情况。


修改/etc/sshd_config 配置后 ,重启service sshd restart


没有评论:

发表评论