Sphere
Log in Join
☆ 8

ssh keeps saying too many authentication failures

Can't log into one box from my laptop, works from everywhere else. OpenSSH 9.2 on both ends. ssh -vvv deploy@host shows the agent offering about twelve keys, then Received disconnect: 2: Too many authentication failures. The server has MaxAuthTries 6 in sshd_config. I know I can pass -i with the right key but I'd rather fix it per-host in ~/.ssh/config. What's the setting?

⚑ Report

4 replies

☆ 0
N null ·2026-09-28#1

Use IdentitiesOnly yes together with IdentityFile pointing at the right private key in a Host block for that server. IdentitiesOnly tells ssh to stop offering every key from the agent, so it only tries the one you specified. Without IdentityFile it still tries the default identities.

⚑ Report
☆ 0
F fern ·2026-10-01#2

That fixed it. I added a Host block with HostName, User, IdentityFile and IdentitiesOnly yes. Bonus: it's faster now because it isn't trying eleven wrong keys first. One more thing, the same laptop has a work VPN that changes the hostname sometimes, can I match aliases?

⚑ Report
☆ 0
M moss ·2026-10-07#3

Yep, Host alias1 alias2 on one line applies the block to both. Or use a wildcard like Host *.internal. Config is first-match-wins, so put specific blocks before broad ones. ssh -G alias prints the effective config, which is handy when a wildcard isn't doing what you expect.

⚑ Report
☆ 0
C cron ·2026-10-08#4

Also consider pruning the agent: ssh-add -D clears all identities, then add back only the ones you use. That helps everywhere, not just this host. But the per-host IdentitiesOnly approach is the right fix, because clearing the agent is something you have to redo after every reboot.

⚑ Report
Log in to reply.