You have the correct private key on disk. You can see it. And the server still throws you out with Received disconnect from host port 22: Too many authentication failures. The key is not the problem — the order in which ssh-agent offers your keys is.
This one catches people who have done everything right. You generated a key, added it to the server, loaded it into your agent. Then, months later, connecting to a different host fails before SSH ever tries the key that would have worked. The cause is a mismatch between how your client offers keys and how the server counts attempts, and the fix is two lines of configuration once you understand what is actually happening on the wire.
What the error actually means
Every SSH server enforces a limit on how many authentication attempts a single connection may make. In OpenSSH that limit is MaxAuthTries, and its default is six. Each public key your client offers counts as one attempt, whether or not you own the matching private key. The server does not know in advance which of your keys is the right one; it only sees a sequence of offers and rejects each until one succeeds or the counter runs out.
Free · 4 minutes
Would you survive contact with a determined attacker — or an auditor?
Fourteen questions on access, patching, detection, and recovery — the basics that prevent most real incidents, and the ones most often assumed rather than verified. Banded finding on screen, full sheet by email.
Here is the trap. When you run ssh-add without arguments, or let your login session load every key it can find, ssh-agent ends up holding all of them. On a connection, your client offers those keys to the server one after another, in the order the agent lists them, before it falls back to any key named in your config. If you have seven or eight keys loaded and the correct one is near the end of the queue, the server hits MaxAuthTries and disconnects you while the working key is still waiting its turn. You are not being rejected for having the wrong key. You are being rejected for offering too many keys the server does not want first.
Prove it with ssh -v
Do not guess. Run the connection in verbose mode and read what your client offers, in order:
ssh -v git@example.com 2>&1 | grep -Ei 'offering|authentications that can continue|too many'
You will see a run of lines like debug1: Offering public key: /Users/you/.ssh/id_ed25519_work agent, one per key, each followed by the server declining it. Count them. If there are six offers and then the disconnect, you have found your cause exactly: the agent burned the whole budget on keys the server was never going to accept. The word agent at the end of those lines tells you the offer came from ssh-agent, not from your config file — which is the distinction the fix turns on.
The fix: IdentitiesOnly with an explicit IdentityFile
The permanent fix is to tell SSH, per host, exactly which key to use and to stop it offering anything else. That is what IdentitiesOnly=yes does: it restricts the client to the identity files named in your config for that host, even when the agent is holding a dozen others. Put this in ~/.ssh/config:
# ~/.ssh/config
# One key per host, and only that key is offered.
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Host prod-bastion
HostName bastion.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
IdentitiesOnly yes
# A safe default for everything else: still use the agent,
# but never offer more than one key before giving up.
Host *
IdentitiesOnly yes
IdentityFile ~/.ssh/id_ed25519
With IdentitiesOnly yes set, the client offers only the IdentityFile you named. One offer, one attempt, well inside the server’s budget. Reconnect with ssh github-work and the verbose output now shows a single offer followed by success. The agent still holds your keys and still supplies the passphrase-free signing — you have simply stopped it from volunteering keys the target does not want.
One detail worth knowing: when IdentitiesOnly is set and you name a private key that is already loaded in the agent, OpenSSH matches it against the agent copy by its public half, so you still get the agent’s cached signing rather than a passphrase prompt. You do not lose the convenience of the agent by naming the file explicitly.
Prune the agent while you are here
Configuration fixes the routine path; a bloated agent is still worth tidying. List what is loaded and clear it if it has grown without you noticing:
# See every key the agent is currently holding
ssh-add -l
# Remove all of them
ssh-add -D
# Add back only the one you need, for four hours
ssh-add -t 4h ~/.ssh/id_ed25519_work
Loading keys with a lifetime using -t keeps the agent from silently accumulating every key you have ever touched, which is the state that produces this error in the first place. It is also better hygiene: a key that expires from the agent is a key an attacker cannot use through a hijacked agent socket hours later.
The server side, briefly
If you administer the host, resist the temptation to raise MaxAuthTries in sshd_config to make the symptom go away. The limit is a defence against brute-force and credential-stuffing attempts, and raising it weakens every account on the box to paper over one client’s misconfiguration. The correct place to fix a client that offers too many keys is the client. Leave the server’s budget where it is; it is protecting you.
This is the same discipline that runs through any credential problem: know exactly what identity is being presented, to whom, and stop presenting everything by reflex. It is the client-side echo of the argument for explicit mutual identity between services, and it belongs to the same family of small, high-leverage fixes as sorting out a 413 on a file-upload endpoint or choosing the right swap configuration on a server. Read the verbose log, name one key per host, and the disconnect stops for good.
Build and rescue work
Hands-on delivery of this kind is handled by Sixteen Pillars Studio.
Free interactive tool
Website compliance checklist
What your site has to do, based on what it actually does
Answer as much or as little as you like — the list builds as you go. Nothing is stored against your name and no email is required.
Everything that applies
Ordered by what to do first: legal requirements you can close quickly, then larger pieces of work, then what is expected rather than required. Not exhaustive, and not a legal audit.
Dated PDF, yours to keep or circulate.
Most technology problems are not technology problems. They are control problems.
The systems exist. The investment has been made. The question is whether leadership can understand, direct, evidence, and sustain what those systems produce. Find out where control exists — and where it only appears to.