I recently had an interesting issue where I SSH login failures in to both work and personal servers. When I tried to log in, I’d immediately get
Received disconnect from w.x.y.z port 22:2: Too many
authentication failures for funnelfiasco
This was a surprise, because I hadn’t tried to log in for a while. Why would I get “too many authentication failures”? I knew we ran fail2ban on the work servers and I figured my web host used something like that, too, so I thought maybe something was triggering a ban.
I checked that there wasn’t something on my network that was generating SSH attacks. tcpdump didn’t show anything (whew!).
It turns out that the issue is due to how the SSH agent works. The SSH agent holds your SSH keys. This allows you to remote into a Unix server with a key without having to re-type your passphrase every time. This is really useful behavior, especially if you make remote connections regularly (whether directly SSHing or using something like git over SSH). But it has some behaviors that can cause problems.
By default, if you have an SSH agent running, it will send all of the keys in the agent, even if you’ve explicitly specified the identity to use. If you have more keys than the server’s MaxAuthTries setting, you may end up with too many login attempts before it gets to the one you want. If you don’t want this behavior, you can add
IdentitiesOnly yes to your SSH config file.