Sep 6, 2022 1 min read

Fix for "Too many authentication failures" SSH connections

Fix for "Too many authentication failures" SSH connections

The problem

When setting up RSA certificate authentication I ran into this small issue. As you gain more and more IDs in your /.ssh folder you will start to run into the issue below.

Received disconnect from X.X.X.X port 22: 2: Too many authentication failures

If you run your ssh command with verbose you can see all the IDs that your ssh client is trying to connect with. After so many connections the host locks you out and you can longer authenticate.

debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\cfree/.ssh/id_rsa RSA SHA256:PZdMZcY5wQZrnG1flkVP/1iEy8xRB6SA83kCj3cpnNg
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: C:\\Users\\cfree/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\cfree/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\cfree/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\cfree/.ssh/id_xmss
debug1: Next authentication method: keyboard-interactive

The quick and dirty way to do this would be to delete all your identities via the ssh-add command.

ssh-add -D

The way to make it work without deleting your identities is to add the -o switch like below.

ssh -o IdentitiesOnly=yes "SERVER"

If you find yourself running into this a lot or want to configure this switch per host you can edit your /.ssh/config in the following ways.

All hosts use the switch

Host * 
       	IdentitiesOnly=yes

Single hosts use the switch

Host SERVER
        IdentitiesOnly=yes
Bonus

You can also use this file to specify additional options per host by default like username, RSA key path, or port.

Host SERVER
        User USERNAME
        IdentityFile PATH_TO_ID
        Port PORT
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Nimbus Code.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.