linux 问题: ssh登录报错,ssh_exchange_identification,多次几次可以登录


  1. 分析

怀疑是句柄数不够,和ssh的最大登录限制

  1. 确认

2.1 确认句柄数

过程:

 ~# systemctl status sshd | grep -i pid  
 Main PID: 3767395 (sshd)

 ~# lsof -p 3767395 | wc -l
82

# sysctl -a | grep fs.file-max
fs.file-max = 9223372036854775807

结论:
不是这个问题

2.2 确认是否ssh最大登录限制

过程:
查看文档:sshd_config文档

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
             forwarding.  The default is 10.

## 同一地址的最大登录数

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).
## 未验证链接的最大并大数

结论:
sshd确实有登录限制

  1. 处理
    修改 /etc/ssh/sshd_config,
    将 MaxStartups 给成 1000,
    重启 sshd。

  2. 验证
    问题解决。