You can have the correct SSH key and still be rejected before the server gets a chance to use it. If ssh-agent has several identities loaded, the SSH client may offer them in sequence. The server counts unsuccessful authentication attempts, and its limit can be reached before your intended key is offered.
This is different from a server rejecting the right public key. The fix is usually to narrow which identities the client offers for that connection—not to change server authentication settings.
Check which keys the agent has loaded
List the identities currently available through your agent:
ssh-add -l The output includes key fingerprints and, depending on the key, a comment. If the agent has multiple keys, SSH may try identities from the agent as well as identities discovered in its configuration and default key files. The exact offer sequence can depend on your client configuration and OpenSSH version.
If the server’s limit is reached first, the client may report an error like Too many authentication failures. That message does not prove that the intended key is invalid: it may not have been offered at all.
Try the intended key without unrelated agent identities
For a one-time test, specify the key and tell SSH to use only identities explicitly configured for the connection:
ssh -o IdentitiesOnly=yes -i ~/.ssh/work_ed25519 user@example.com -i selects an identity file. IdentitiesOnly=yes restricts public-key authentication to configured identities rather than offering every identity the agent makes available. If the private key is encrypted and loaded in your agent, SSH can still use the corresponding agent identity when it matches the configured key.
If you want to test the private key file without using the agent at all, you can also disable the agent for this connection:
ssh -o IdentityAgent=none -o IdentitiesOnly=yes \ -i ~/.ssh/work_ed25519 user@example.com This can help distinguish an agent-order problem from a key-file problem. It may prompt for the private key’s passphrase. Don’t remove all keys from a shared or long-running agent just to test one host; that can disrupt other sessions or tools.
For more detail about what the client offers, run:
ssh -vvv -o IdentitiesOnly=yes -i ~/.ssh/work_ed25519 user@example.com Look for lines such as Offering public key. Check whether the intended key is offered, and whether that happens before the connection is rejected. Verbose logs can contain usernames, hostnames, and key fingerprints, so review them before sharing.
If the intended key is offered and rejected, you may have a different issue: the matching public key might not be authorized for that account, or the server may reject it for another reason. See this guide to diagnosing SSH Permission denied (publickey) rather than assuming the agent order is still the cause.
Make the choice persistent with SSH config
Add a host-specific entry to ~/.ssh/config:
Host work-server HostName example.com User user IdentityFile ~/.ssh/work_ed25519 IdentitiesOnly yes Connect using the alias:
ssh work-server The Host pattern determines when the settings apply. In this example, they apply when you run ssh work-server, not automatically whenever you connect to example.com. If you prefer to use the real hostname as the command, use Host example.com instead.
Keep the rule specific to the server that needs this key. A broad Host * rule with one IdentityFile can unintentionally affect other hosts. If you have multiple keys for different services, use separate host aliases or specific patterns. OpenSSH reads configuration in order, and for many settings the first obtained value takes precedence; put more specific rules before broader ones. More examples are available in this practical guide to OpenSSH config files.
To inspect the effective settings for an alias, use:
ssh -G work-server | grep -E '^(hostname|user|identityfile|identitiesonly) ' ssh -G prints the configuration the client would use without making a connection. On Windows, the OpenSSH client also supports SSH config and these command-line options; see the PowerShell SSH guide for Windows-specific connection setup.
Don’t raise the server limit as the first fix
The server’s MaxAuthTries setting limits failed authentication attempts on a connection. Raising it may mask a client that is offering the wrong identities, while allowing more failed attempts per connection. Unless you administer the server and have a specific reason to change its policy, fix the client’s identity selection instead.
If you control the server, its SSH logs can help confirm whether the connection exhausted the attempt limit. Avoid repeatedly retrying with the same unfiltered agent: each new connection can hit the same limit. Test with IdentitiesOnly=yes, verify the intended key is offered, then save the host-specific rule once it works.
I'm building ShadeTerm — an SSH client that organizes terminals, SFTP, code editing, and server tools into workspaces.