Stop your SSH agent from holding onto old identities forever
SSH & Remote Administration
Stop your SSH agent from holding onto old identities forever
🧩 The Challenge
You know that feeling when you keep hitting ‘permission denied’ even though you just updated your SSH key? It turns out your local SSH agent is just stubbornly re-offending with the old, expired key before the remote host even gets a chance to see the new one.
💡 The Fix
You need to tell your client to only offer the keys you actually want to use for that specific host, skipping the agent’s hoard entirely. This stops the “too many authentication failures” error from killing your connection before you get a prompt.
Host myserver.com
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa_specific
⚙️ Why It Works
Setting IdentitiesOnly to yes tells the client to ignore whatever keys are currently loaded in your agent and stick strictly to the file you defined. It forces a clean handshake every single time.
🚀 Pro-Tip: Toss this in your ~/.ssh/config so you never have to deal with the agent clutter again.
Linux Tips & Tricks | © ngelinux.com | 9/12/2026
