Fix SSH Too Many Authentication Failures
In this article
The "Too many authentication failures" error occurs when an SSH client sends more authentication attempts than the server allows before a successful login. The fix is to reduce the number of keys offered or explicitly specify the correct key and user, and you can also increase the server's limit. This article explains the cause and provides step-by-step solutions for both client and server configurations.
Why This Error Happens
SSH authentication is a negotiation process. By default, the OpenSSH client tries every private key it has loaded (from ~/.ssh/ or an agent) in order, one by one, until the server accepts one or runs out of patience. The server has a setting called MaxAuthTries (default is 6) that limits how many failed attempts it will tolerate before dropping the connection. When you have many keys in your ~/.ssh/ directory or an SSH agent holding multiple identities, the client may exhaust this limit before it ever tries the key the server actually wants.
This is especially common if you use an SSH agent (like ssh-agent or a keychain) that automatically loads many keys, or if you have accumulated several keys over time. The error message itself—Too many authentication failures—appears after the client has tried all its keys and the server has closed the connection.
Quick Fix: Specify the Key and User
The most direct solution is to tell SSH exactly which key and username to use, bypassing the automatic trial-and-error. Use the -i option to point to the private key file, and -l to specify the username (or use user@host syntax).
- Find the correct private key file (e.g.,
~/.ssh/id_ed25519or~/.ssh/id_rsa). - Run:
ssh -i ~/.ssh/id_ed25519 user@server.com - If you use an SSH agent, disable it temporarily with
ssh -ato avoid it offering other keys.
This approach works immediately and is the recommended way when you know which key is required. If you're unsure which key the server expects, check the server's ~/.ssh/authorized_keys file (if you have access) or contact the administrator.
Client-Side Configuration
If you frequently connect to the same servers, you can create a per-host configuration in ~/.ssh/config to always use the correct key and user. This prevents the client from offering all keys.
Host myserver
HostName server.example.com
User myusername
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
The IdentitiesOnly yes directive tells SSH to use only the keys specified in the config (or on the command line), ignoring keys from the agent or the default directory. This is a clean, permanent fix.
Another client-side option is to reduce the number of keys in your ~/.ssh/ folder. Move unused keys to a backup directory (e.g., ~/.ssh/backup/) so they aren't offered automatically. Be sure to keep the corresponding public keys in ~/.ssh/*.pub if needed.
Server-Side Fix: Increase MaxAuthTries
If you administer the server, you can increase the allowed number of authentication attempts. Edit the SSH daemon configuration file, usually /etc/ssh/sshd_config, and set:
MaxAuthTries 10
Then restart the SSH service: sudo systemctl restart sshd (on systemd-based systems) or sudo service ssh restart on older init systems. A higher number gives the client more room to try multiple keys, but it also increases the risk of brute-force attacks. Keep it as low as practical—10 is often enough for most setups.
Note that the client also has a limit (NumberOfPasswordPrompts for passwords, but for keys it's the number of keys offered). The server's MaxAuthTries is the one that triggers the error message.
Using SSH Agent Safely
SSH agents are convenient but can cause this error. If you use an agent, you can list the loaded keys with ssh-add -l and remove unwanted ones with ssh-add -d (specific key) or ssh-add -D (all keys). To prevent the agent from auto-loading keys, configure your shell to not start ssh-agent automatically, or use a tool like keychain with careful options.
Alternatively, you can use the IdentitiesOnly option even with an agent—the client will still use the agent for the specified key, but won't offer others.
Common Misconceptions
Many users think the error means the password is wrong or the server is blocking them. In reality, it's a negotiation failure, not a credential failure. The server never even gets to check the correct key because the client runs out of attempts first.
Another misconception is that deleting all keys except the correct one is the only fix. While that works, it's not necessary if you use IdentitiesOnly or specify the key explicitly.
Also, note that the error can occur with password authentication if the client tries multiple passwords (e.g., from a script). The same MaxAuthTries limit applies.
Frequently Asked Questions
How do I see which keys SSH is offering?
Run ssh -vvv user@host to see verbose output. It will list each key it tries, e.g., Offering public key: /home/user/.ssh/id_rsa. This helps identify the offending keys.
Can I increase the client's limit?
The client doesn't have a configurable limit for the number of keys offered; it offers all available keys. You can limit which keys are offered using IdentitiesOnly or by removing keys from the agent.
What is the default MaxAuthTries value?
The default in OpenSSH is 6. This means the server allows up to 6 authentication attempts before disconnecting.
Does this error affect SCP or SFTP?
Yes, because SCP and SFTP use the same SSH transport. The same fixes apply—use -i or configure ~/.ssh/config.
Is it safe to set MaxAuthTries to a very high number?
No. A high number makes brute-force attacks easier. Keep it as low as possible while still accommodating legitimate multi-key setups. 10 is a reasonable compromise.