The Error

bash
Received disconnect from 192.168.1.100 port 22:2: Too many authentication failures

This happens when your SSH client tries too many keys before finding the right one.

Why This Happens

By default, SSH tries all keys in your agent and ~/.ssh/ directory. If you have 6+ keys and none match, the server cuts you off (default MaxAuthTries is 6).

Quick Fix: Specify the Key

Tell SSH exactly which key to use:

bash
ssh -i ~/.ssh/my_server_key user@server

Permanent Fix: Configure Keys Per Host

Add to ~/.ssh/config:

bash
Host myserver
  HostName server.example.com
  User admin
  IdentityFile ~/.ssh/my_server_key
  IdentitiesOnly yes

The IdentitiesOnly yes option tells SSH to only use the specified key, not others from your agent.

Check Your SSH Agent

See how many keys your agent has:

bash
ssh-add -l

If you have many keys, the server might reject you before trying the right one.

Option 1: Clear the Agent

```bash # Remove all keys ssh-add -D

# Add only the one you need ssh-add ~/.ssh/my_server_key ```

Option 2: Increase Server MaxAuthTries

If you control the server, increase the limit in /etc/ssh/sshd_config:

bash
MaxAuthTries 10

Restart sshd:

bash
sudo systemctl restart sshd

Debug Which Keys Are Tried

bash
ssh -v user@server 2>&1 | grep "Offering public key"

You'll see each key being offered:

bash
debug1: Offering public key: /home/user/.ssh/id_rsa
debug1: Offering public key: /home/user/.ssh/id_ed25519
debug1: Offering public key: user@workstation RSA SHA256:...

Best Practice

Configure each host explicitly rather than relying on SSH to find the right key:

``` # ~/.ssh/config Host github.com IdentityFile ~/.ssh/github_key IdentitiesOnly yes

Host production-server HostName prod.example.com IdentityFile ~/.ssh/prod_key IdentitiesOnly yes

Host staging-server HostName staging.example.com IdentityFile ~/.ssh/staging_key IdentitiesOnly yes ```

This prevents SSH from offering too many keys and getting disconnected.