Twitter icon LinkedIn Icon Github Icon Stackoverflow Icon

SSH - Too Many Authentication Failures

By: Roger Creasy

There are a handful of possible reasons for this error. Perhaps the problem is exactly what is says; you have tried and failed to log in too many times. Maybe your ssh configuration on the server side doesn't allow you to log in at all. Or, you could be blocked by Fail2Ban, if you are running it on your server (and you should!).

If you have multiple ssh keys on your local machine, like I do, the problem could be the number of keys you have. When you attempt to contect via ssh, by default ssh attempts each key until it finds one that is accepted, or until you reach the number of attempts limit. Having lots of keys means there could be a lot of attempts. Reaching the number of attempts limit, and how to avoid this problem, is what we are dicussing here.

To avoid this issue, when connecting via ssh tell the system which key to use. You can do this with a command line switch when you enter the connect command.

ssh -i /path/to/key user@server-ip

If you are using rsa keys, your username on the server is roger, your server is at the ip, and your key is in the default location, the command would look like the following.

ssh -i ~/.ssh/id_rsa roger@

With the above ssh attempts first to connect with the key you specify.

If you use a local ssh config file, you can tell ssh which key to use there. Set your config file up at ~/[username]/.ssh/config with the content below. NOTE: this entry is for one server only. Your config file can have multiple entries -- one for each server.

Host myServer
User roger
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa

Above I used the same info as the previous example. You need to name your Host whatever you want, set the Hostname to your server's IP, and put the path to your key next to IdentityFile. Save the config file. Now, you can ssh to the server using the following.

ssh myServer

When you enter the above, ssh will use your config file to fill in your username and your key.

In future posts I plan to write more about using an ssh config file. There are many things it can do to make life easier.

If you have questions, feel free to contact me. I am happy to help if I can.

Publication Date: 2020-02-07 17:41:11