If you keep separate SSH keys (work versus personal, prod versus staging, one GitHub account versus another), the problem is making SSH pick the right one automatically. The answer is ~/.ssh/config: bind each key to the host that should use it.
Why you get "too many authentication failures"
By default SSH offers every key it can find, in order, until one works or the server cuts you off (MaxAuthTries, usually 6). With several keys loaded you can exhaust that limit before the correct key is tried, and the server returns Too many authentication failures. The fix is to tell SSH exactly which key goes with which host, and to offer only that one.
A config that maps keys to hosts
# ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
Host work-git
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Host prod
HostName prod.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
IdentitiesOnly yes
IdentitiesOnly yes is the important line: it stops SSH from offering any key except the listed IdentityFile, which is what prevents the "too many failures" cutoff.
Two GitHub accounts on one machine
This is the classic case. GitHub identifies you by the key, not the URL, so you cannot use git@github.com for both. Use a host alias for the second account (the work-git block above), then point the repo at the alias:
git clone git@work-git:company/repo.git
# or change an existing repo's remote:
git remote set-url origin git@work-git:company/repo.gitPersonal repos keep using git@github.com:...; work repos use git@work-git:.... Each resolves to github.com but offers a different key.
Test which key a host will use
ssh -T git@github.com # personal account
ssh -T git@work-git # work accountGitHub answers Hi USERNAME! with the account the offered key belongs to, so you can confirm each alias maps to the right identity.
FAQ
See also
- How to Create an SSH Key in 2026: generate the separate keys you are mapping here.
- Add an SSH key to GitHub and GitLab: register each key with its account.
- Fix SSH "Permission denied (publickey)": when the wrong key is the cause.
- SSH Cheat Sheet: the full ~/.ssh/config directive reference.
Sources
Authoritative references this article was fact-checked against.
- ssh_config(5) manual page (OpenBSD)man.openbsd.org





