Fixing 'Too Many Authentication Failures' When Connecting SSH to a Server

intermediate🐧 Linux2026-03-28| Client OS: Linux (e.g., Ubuntu, Fedora, CentOS), macOS, WSL. Server OS: Linux (any distribution running OpenSSH server). Software: OpenSSH client and server.

Error Message

Received disconnect from 192.168.1.100 port 22:2: Too many authentication failures Authentication failed.
#ssh#authentication#openssh#linux

Context: The Frustration of SSH Disconnects

Picture this: you're trying to SSH into a server. Maybe it's a brand-new one you just provisioned, or perhaps an old friend you haven't touched in a while. You're confident about the username and the server's IP address. But instead of the familiar password prompt or a smooth key-based login, you're abruptly disconnected. A confusing message appears, often after a brief pause, leaving you wondering if the server even bothered to check your credentials.

This specific error, Too many authentication failures, is a common and frustrating obstacle, especially for users who manage many SSH keys or have a disorganized ~/.ssh directory. Essentially, the server is telling you, "You've tried too many different ways to prove your identity during this single connection attempt, so I'm cutting you off."

The Exact Error Message You're Seeing

Received disconnect from 192.168.1.100 port 22:2: Too many authentication failures
Authentication failed.

Debug Process: Unpacking the 'Too Many' Mystery

When you encounter "Too many authentication failures" followed by a disconnect, it's usually not because your specific key or password is incorrect (though that's always a possibility). Instead, your SSH client is likely offering too many different authentication methods to the server in a single connection attempt.

The server imposes a limit, often controlled by the MaxAuthTries setting (which typically defaults to 6 on many OpenSSH servers). Once this limit is reached, the server becomes suspicious and simply closes the connection.

Step 1: Get Verbose SSH Output

The first step in debugging any SSH issue is to add the -v flag (or multiple -vvv for even more detail). This will show you exactly what your client is doing, including which keys it's attempting to use.

ssh -v user@your_server_ip

Look for lines similar to these in the output:

debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/youruser/.ssh/id_rsa RSA SHA256:... agent
debug1: Server accepts key: /home/youruser/.ssh/id_rsa RSA SHA256:...
debug1: Offering public key: /home/youruser/.ssh/id_dsa DSA SHA256:... agent
debug1: Offering public key: /home/youruser/.ssh/id_ecdsa ECDSA SHA256:... agent
debug1: Offering public key: /home/youruser/.ssh/id_ed25519 ED25519 SHA256:... agent
debug1: Offering public key: /home/youruser/.ssh/my_project_key RSA SHA256:... agent
debug1: Offering public key: /home/youruser/.ssh/another_old_key RSA SHA256:... agent
... (more keys being offered)
Received disconnect from 192.168.1.100 port 22:2: Too many authentication failures
Authentication failed.

If this output reveals your client offering numerous public keys, you've likely identified the root cause. Your client is attempting to use every key it finds in your ~/.ssh/ directory, plus any loaded into your ssh-agent. The server, in turn, hits its internal MaxAuthTries limit before you even have a chance to offer the correct key or password.

Solution: Limiting Your Client's Enthusiasm

The core solution involves instructing your SSH client to be more selective in offering its keys. You need to tell it precisely which identity to use for a particular connection.

Method 1: Explicitly Specify the Identity File (Quick Fix)

The fastest way to bypass this issue for a single connection is to tell SSH exactly which private key file to use with the -i flag.

ssh -i ~/.ssh/path/to/your/correct_private_key user@your_server_ip

For example, if your private key for the server is ~/.ssh/server_prod_key:

ssh -i ~/.ssh/server_prod_key your_username@192.168.1.100

This forces the client to offer only that specific key, drastically reducing the number of authentication attempts.

Method 2: Configure Your SSH Client (Permanent Fix)

For a more permanent and cleaner solution, especially if you connect to this server frequently, you should configure your SSH client's behavior in its configuration file, ~/.ssh/config.

  • Create or Edit ~/.ssh/config: If the file doesn't exist, create it. Make sure its permissions are strict (chmod 600 ~/.ssh/config).
  • Add a Host Entry: Add a block for your server, specifying IdentitiesOnly yes and IdentityFile.
Host your_server_alias
    HostName 192.168.1.100
    User your_username
    IdentitiesOnly yes
    IdentityFile ~/.ssh/path/to/your/correct_private_key
    # Port 22 # Uncomment and change if your SSH server uses a different port
    # PreferredAuthentications publickey # Optional: Prioritize key auth

Replace your_server_alias, 192.168.1.100, your_username, and ~/.ssh/path/to/your/correct_private_key with your actual values.

Now, you can connect simply using the alias:

ssh your_server_alias

The IdentitiesOnly yes directive is crucial here. It instructs the SSH client to use only the authentication identity files explicitly configured for that host via IdentityFile. This means it will ignore any keys loaded in ssh-agent or other default identity files found in ~/.ssh/.

Method 3: Manage Your SSH Agent (If Applicable)

If you're using ssh-agent and have loaded many keys into it, your client might be offering all of them. You can manage the keys loaded into your agent:

  • List loaded keys:

ssh-add -l

  
  - **Remove all keys from the agent:** (Use with caution, as this affects all current connections using the agent)
    ```bash
ssh-add -D
  • Add only the specific key(s) you need:

ssh-add ~/.ssh/path/to/your/correct_private_key

  

This method is particularly useful if the primary issue stems from an overstuffed `ssh-agent`, rather than a cluttered `~/.ssh` directory or the client's default behavior.

### Server-Side Considerations (Less Common for This Error)
While this error is primarily a client-side issue, it's worth briefly understanding a server-side setting: `MaxAuthTries` in `/etc/ssh/sshd_config`. This setting dictates the maximum number of authentication attempts the server will permit per connection.

The default value is typically 6. So, if your client is configured to send, say, 10 keys, you'll inevitably hit this limit. However, for the specific 'Too many authentication failures' message, the client is almost always the one at fault for offering too many options.

If you *were* to modify this on the server (which is generally not recommended unless you have a strong reason, as it can reduce security):

```ini
# On the server, edit /etc/ssh/sshd_config
MaxAuthTries 10 # Increase this value, then restart sshd

Remember to restart the SSH daemon after any changes to sshd_config:

sudo systemctl restart sshd # For systemd-based systems
# OR
sudo service sshd restart # For older init systems

Again, this is rarely the primary fix for Too many authentication failures, which usually means the client is sending too many different keys, not just repeatedly failing with one.

Verification: Confirming the Fix

After applying one of the solutions above (preferably Method 1 or 2), try connecting to your server again:

ssh user@your_server_ip # If using Method 1 for a one-off
# OR
ssh your_server_alias # If using Method 2 with ~/.ssh/config

If the fix worked, you should now either be prompted for your SSH key passphrase (if your key has one) or directly logged into the server. Alternatively, you might be prompted for a password if key authentication isn't set up or failed for the correct key.

Lessons Learned & Prevention

  • Keep ~/.ssh Tidy: Regularly review your ~/.ssh directory. Remove old, unused, or duplicate key pairs. A cluttered ~/.ssh directory is a common cause of this error.
  • Be Explicit with SSH Config: Using ~/.ssh/config with IdentitiesOnly yes and IdentityFile for each host you connect to is a best practice. This approach makes your connections predictable and effectively prevents this specific error.
  • Understand SSH Agent: If you use ssh-agent, be mindful of how many keys you have loaded. While convenient, too many can lead to this issue.
  • Secure Your Keys: Always protect your private keys with strong passphrases.

Tool Recommendation: For Strong Passwords and Security

While SSH keys are generally preferred for server access, you might still need strong passwords for initial setup, system accounts, or other related services. When I need to generate a truly random and robust password, I often turn to ToolCraft's Password Generator.

It's a simple, browser-based tool that's particularly useful because it processes all generation locally—meaning no data ever leaves your browser, a significant advantage for privacy. You can find it at https://toolcraft.app/en/tools/security/password-generator. It's a handy utility to keep in your toolkit for any situation requiring robust credentials.

Related Error Notes