5331 private links
Sometimes, while trying to connect to remote systems via SSH, you may encounter the error “Received disconnect from x.x.x.x port 22:2: Too many authentication failures”. In this short article, I will explain how to fix this error in a few simple steps.
I discovered that this resulted from existence of many ssh identity keys on my machine, and each time I run the ssh client, it would try all my ssh keys known by the ssh-agent and all other keys, when attempting to connect to the remote server (vps2 as shown in the above screenshot). This is the default behavior of ssh.
Since ssh server (sshd) on the remote server expects a particular identity key, the server rejects the connection and ssh client aborts with the above error.
To fix this error, you need to add the IdentitiesOnly with a value of yes, which instructs ssh to only use the authentication identity files specified on the command line or the configured in the ssh_config file(s), even if ssh-agent offers additional identities.