Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

SSH "Received disconnect: Too many authentication failures": how an agent full of keys uses up the server's attempts

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

The client message reads Received disconnect from 203.0.113.10 port 22:2: Too many authentication failures. The server counts each failed authentication attempt on a connection and disconnects the client when the count reaches MaxAuthTries, which defaults to 6. A client with many keys in ssh-agent can use all six attempts on wrong keys before it tries the right one. Tell ssh which key to use for that host and stop it offering the others.

What the error means

The sshd_config manual describes MaxAuthTries as "the maximum number of authentication attempts permitted per connection" and says "Once the number of failures reaches half this value, additional failures are logged. The default is 6."

The next two paragraphs come from the OpenSSH source code (release V_10_6_P2), not from a manual page. In auth2.c, a failed authentication request adds one to a failure counter, except for an initial none request. When the counter reaches the limit, the server calls a routine in auth.c that logs the format maximum authentication attempts exceeded for %s%.100s from %.200s port %d ssh2 and disconnects with the text Too many authentication failures. In that format the first %s is empty or the words invalid user , then come the user name, the client address and the port.

The client prints the disconnect with the format Received disconnect from %s port %d:%u: %.400s (packet.c). The first %s is the server address, %d the port, %u the disconnect reason code and the last field the message text.

The ssh_config manual explains why one user can hit this alone. IdentityFile defaults to the standard files in ~/.ssh, "Additionally, any identities represented by the authentication agent will be used for authentication unless IdentitiesOnly is set". The IdentitiesOnly entry adds that it "is intended for situations where ssh-agent offers many different identities". Every offered key the server does not accept is a failure.

Likely causes

Cause What you see How to confirm
The agent holds many keys and the right one is not among the first few Error before any password prompt, on a host you reach with a specific key ssh-add -l lists more keys than MaxAuthTries allows
Wildcard Host * block with several IdentityFile lines Every host offers the same long list ssh -G for the host shows many identityfile entries; the manual says multiple IdentityFile directives "add to the list of identities tried"
Server MaxAuthTries set lower than the default Error with only two or three keys On the server, sshd -T shows the effective setting
The correct key is not authorised on this server Every key fails, then the disconnect The server log shows the failures; see SSH "Permission denied (publickey)": what the server log says and what to fix
Repeated wrong passwords after key failures The disconnect comes during password prompts Each failed password attempt counts too; NumberOfPasswordPrompts defaults to 3 on the client

Prove the cause before changing anything

All of these are read-only.

1. How many keys does the agent hold? The ssh-add manual says -l lists the fingerprints of all identities currently represented by the agent:

ssh-add -l

Count the lines. A good result for this fault is a short list that includes the right key. A bad result is more keys than MaxAuthTries, or the right key far down the list.

2. What will ssh actually offer for this host? The ssh manual says -G prints the configuration after evaluating Host and Match blocks:

ssh -G admin@web01.example.com

Read the identity file lines. Remember that the agent's keys are in addition to these unless IdentitiesOnly is yes.

3. What happens during the connection. The ssh manual says -v prints debugging messages about progress, which it calls helpful for debugging authentication problems, and that more -v options increase the detail, up to 3:

ssh -v admin@web01.example.com

Count the keys the client tries before the disconnect line appears.

4. What does the server allow? If you manage the server, the sshd manual says -T outputs the effective configuration:

sshd -T

Look for the effective MaxAuthTries. The server's own log shows the line maximum authentication attempts exceeded for followed by the user, address and port.

Fix

Connect once with a named key

The ssh manual says -i selects the file from which the identity is read, and the ssh_config manual says IdentitiesOnly limits ssh to the configured identity files "even if ssh-agent(1) or a PKCS11Provider or SecurityKeyProvider offers more identities". This command changes no configuration file:

ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519_web01 admin@web01.example.com

If this connects, the cause is confirmed: too many offered keys.

Make it permanent for one host

The ssh_config manual says IdentityFile "may be used in conjunction with IdentitiesOnly to select which identities in an agent are offered during authentication."

First save the current file. If ~/.ssh/config does not exist yet, use the one-off command above instead:

cp -p ~/.ssh/config ~/.ssh/config.2026-11-22

Risk: the next edit limits which keys ssh offers to the named host. If the key file name is wrong, or the key is only in the agent and not on disk, the connection will fail. Use Host names narrow enough that other hosts are not affected.

The manual says the first value obtained for each directive is used, so host-specific declarations go near the beginning of the file. Add this block at the top:

Host web01.example.com
    IdentityFile ~/.ssh/id_ed25519_web01
    IdentitiesOnly yes

Check what the client will now use, then connect:

ssh -G admin@web01.example.com
ssh admin@web01.example.com

To undo it: put the saved file back and check it.

cp -p ~/.ssh/config.2026-11-22 ~/.ssh/config
ssh -G admin@web01.example.com

If a key is only in the agent

The ssh_config manual says you can name a public key file in IdentityFile to use "the corresponding private key that is loaded in ssh-agent(1) when the private key file is not present locally". This changes the block from the section above. First save the current file under its own name, separate from the earlier save:

cp -p ~/.ssh/config ~/.ssh/config.pub.2026-11-22

Risk: the next edit changes which key file the block names. If the key is not loaded in the agent, the connection will fail.

Replace the IdentityFile line in the block with the public key file path, for example IdentityFile ~/.ssh/id_ed25519_web01.pub, and keep IdentitiesOnly yes.

To undo it: put that saved file back and check it.

cp -p ~/.ssh/config.pub.2026-11-22 ~/.ssh/config
ssh -G admin@web01.example.com

If the right key is not authorised on the server

No client setting fixes this. Check the server log, then see SSH "Permission denied (publickey)": what the server log says and what to fix.

Example (illustrative): an administrator's agent holds 8 keys, listed by ssh-add -l. The key for web01.example.com is the seventh. The server uses the default MaxAuthTries of 6. The client offers keys 1 to 6 and the server rejects each, so after the sixth failure the counter reaches 6 and the server disconnects with Too many authentication failures. The seventh key is never offered. With the block above, ssh offers only ~/.ssh/id_ed25519_web01, which the server accepts at the first attempt, so the counter stays at 0.

Confirm the fix

  1. ssh admin@web01.example.com connects without the disconnect.
  2. ssh -v admin@web01.example.com shows one key offered, not the whole agent.
  3. Other hosts still work, because the block names only one host.

What to watch afterwards

  • Keep the number of keys in the agent small. Every added key increases the attempts a plain ssh command uses on every host that has no IdentitiesOnly setting.
  • A Host * block with IdentityFile lines adds those keys to every host, as the manual says. Check ssh -G for new hosts.
  • On the server, repeated maximum authentication attempts exceeded lines from one address can also be a password-guessing attempt, not only your own agent. Compare the address with yours before deciding which it is.
  • If a tool that bans addresses after repeated failures has blocked your own address, see fail2ban banned my own IP: unban it, find which jail, and set ignoreip.

Risks and limits

  • These commands have not been run or lab-tested.
  • The count is per connection. A client that reconnects starts again at zero, and each reconnect can use up the attempts again.
  • The MaxAuthTries default and the counting rule are from the current OpenBSD manual page and the OpenSSH source code at tag V_10_6_P2. Check them against the version installed on the server, since older releases may differ.
  • Raising MaxAuthTries on the server is not covered. It allows more guesses per connection from any client.

Sources

  • sshd_config(5) — OpenBSD manual page, 30 October 2026, accessed 22 November 2026
  • ssh_config(5) — OpenBSD manual page, 30 October 2026, accessed 22 November 2026
  • ssh(1) — OpenBSD manual page, 2 November 2026, accessed 22 November 2026
  • ssh-add(1) — OpenBSD manual page, 16 September 2026, accessed 22 November 2026
  • sshd(8) — OpenBSD manual page, 2 September 2026, accessed 22 November 2026
  • auth2.c, tag V_10_6_P2 — OpenSSH portable source code, fixed tag V_10_6_P2, no date shown, accessed 22 November 2026
  • auth.c, tag V_10_6_P2 — OpenSSH portable source code, fixed tag V_10_6_P2, no date shown, accessed 22 November 2026
  • packet.c, tag V_10_6_P2 — OpenSSH portable source code, fixed tag V_10_6_P2, no date shown, accessed 22 November 2026
  • cp(1) — GNU coreutils 9.11 manual page, April 2026, accessed 22 November 2026