What the message looks like
kex_exchange_identification: Connection closed by remote hostCommon causes
- Too many simultaneous unauthenticated connections: the
MaxStartupslimit (default10:30:100) is reached and sshd drops new connections. - A protection service such as fail2ban, or a firewall rule, blocks the source IP only after the TCP handshake.
- TCP wrapper rules in
/etc/hosts.denyforbid the connection (only on builds with support). - sshd has crashed, is restarting or has a configuration error.
- A proxy, load balancer or NAT device between client and server ends the connection.
Check
- Check the server log for dropped connections
- Effective MaxStartups setting (on the server, as root)
sshd -T | grep -i maxstartups - Check fail2ban bans
fail2ban-client status sshd - Client view with verbose output
ssh -vvv user@server.example.com
Fix
- Read the logs on the server: lines mentioning "MaxStartups" show that connections are dropped because of the limit.
- Under brute-force load, use
fail2ban, restrict access by firewall or VPN and allow key login only, instead of just raising the limit. - If legitimate traffic exceeds the limit, raise
MaxStartupsin/etc/ssh/sshd_config, check withsshd -t, then reload the service. - Unban your own IP in fail2ban:
fail2ban-client set sshd unbanip IP; and check/etc/hosts.deny. - If sshd crashed, fix the cause using
systemctl status sshand the journal.
Typical scenario
A public server on port 22 is constantly knocked on by bots. Suddenly the admin also gets an occasional kex_exchange_identification: Connection closed by remote host, and the journal contains drop connection ... past MaxStartups. A script opening many SSH sessions in parallel makes it worse. Fail2ban, key-only login and bundled connections via ControlMaster remove the bottleneck.
FAQ
Is my key or password wrong?
No. The message comes before any authentication. Wrong credentials lead to "Permission denied", not to this abort.
Why does it only happen sometimes?
A limit such as MaxStartups only bites during load peaks, for example scans or parallel scripts. The same connection then works again shortly after.
How does ControlMaster help scripts?
With ControlMaster auto, ControlPath and ControlPersist in ~/.ssh/config, many calls share one existing connection. That saves handshakes and barely touches MaxStartups.
Should I just set MaxStartups very high?
Only with care. The limit protects the server from overload by unauthenticated connections. It is better to reduce the load (fail2ban, firewall, another port) and adjust the limit moderately.
The error only occurs via a jump host. What should I check?
With ProxyJump, first test the jump host directly and then its connection to the target. The abort can happen at either hop; ssh -vvv shows where.