Error Codes Wiki

SSH Too Many Authentication Failures — Connection Rejected After Key Attempts

Warningsecurity

Overview

Fix SSH 'Too many authentication failures' error when the SSH client tries too many keys before finding the correct one, exceeding the server's MaxAuthTries limit.

Key Details

  • SSH clients try all loaded keys (from ssh-agent and config) before falling back to password
  • If you have 5+ SSH keys loaded, the client may exhaust MaxAuthTries (default 6) before trying the right key
  • Each key attempt counts as an authentication try even if the key is wrong
  • The server disconnects after MaxAuthTries is reached, showing 'Too many authentication failures'
  • This commonly affects developers with multiple GitHub, GitLab, and server SSH keys

Common Causes

  • Too many SSH keys loaded in ssh-agent (each is tried sequentially)
  • SSH config (~/.ssh/config) not specifying which key to use for each host
  • Server MaxAuthTries set too low for the number of keys the client offers
  • IdentitiesOnly not set, causing the client to try agent keys in addition to configured keys

Steps

  1. 1Specify the correct key per host in ~/.ssh/config: Host server.com > IdentityFile ~/.ssh/server_key
  2. 2Add 'IdentitiesOnly yes' to the host config to use only the specified key (not agent keys)
  3. 3List loaded agent keys: 'ssh-add -l' — remove unnecessary keys with 'ssh-add -d key_file'
  4. 4Force password auth for testing: 'ssh -o PreferredAuthentications=password user@host'
  5. 5If server admin: increase MaxAuthTries in /etc/ssh/sshd_config (default is 6)

Tags

sshauthenticationtoo-many-failuresssh-agentkeys

More in Security

Frequently Asked Questions

By default, SSH offers all keys from ssh-agent and default key paths (~/.ssh/id_rsa, id_ed25519, etc.) to the server. Without IdentitiesOnly and IdentityFile in your config, every key is tried for every host.