What the message looks like
Received disconnect from 203.0.113.10 port 22:2: Too many authentication failures
Disconnected from 203.0.113.10 port 22
user@203.0.113.10: Permission denied (publickey).Common causes
- The ssh-agent holds many keys and offers them one after another.
- No
IdentityFileis set for the host, so ssh tries all default keys and agent keys. - The right key is not authorized on the server.
MaxAuthTrieson the server is low.- Old keys in
~/.sshare tried first.
Check
- How many keys does the agent hold?
ssh-add -l - Which keys are offered, and in which order?
ssh -v user@server.example.com 2>&1 | grep -iE 'offering|authentications that can continue' - The limit on the server (console or another access)
sshd -T | grep -i maxauthtries
Fix
- Offer only the key you name:
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 user@server.example.com. - Make it permanent in
~/.ssh/config:Host server,IdentityFile ~/.ssh/id_ed25519,IdentitiesOnly yes. - Remove unneeded keys from the agent:
ssh-add -D, then add only what you need withssh-add ~/.ssh/id_ed25519. - Check that the public key is in
~/.ssh/authorized_keyson the server with the right permissions. - Raise
MaxAuthTrieson the server only if you really must; fewer keys is the better fix.
Typical scenario
You manage servers for several customers and have eight keys loaded in ssh-agent. On the first login to a new server with password-only authentication, the server disconnects at once with "Too many authentication failures". Your ssh first offers all agent keys, and the server counts each as a failed attempt. Run ssh -v and count the "Offering public key" lines to see how many keys are offered before the password prompt.
FAQ
Why can I not even type my password?
Key attempts come first. The limit is reached before ssh gets to password authentication.
Is this the same as a ban by fail2ban?
No. This disconnect is a single connection hitting the per-connection limit. A fail2ban ban blocks your address and shows as a timeout or refusal, see port 22 timed out.
How do I test whether password login works without keys?
With ssh -o PubkeyAuthentication=no user@server ssh skips all keys and asks for the password directly. If that works, the server is fine and the problem is only the number of offered keys. The permanent fix is then IdentitiesOnly in your configuration.
Why does ssh offer agent keys although I specified an IdentityFile?
Without IdentitiesOnly yes, ssh tries all keys the agent provides in addition to the named files, sometimes before the named file. Only with that option does it restrict itself to the keys given in the configuration or on the command line.
Should I raise MaxAuthTries on the server instead?
You can in sshd_config (default 6), but it is the worse solution. The value also limits password guessing, and a higher value gives attackers more attempts per connection. It is better to fix it on the client.