Git: fix secondary ssh key unable to access repo (MFA code problem)

The Problem

For some reason after enabling MFA on my secondary (work) GitHub account, I occasionally get a “broken” SSH key loaded into ssh-agent, possibly after entering an incorrect MFA code during my .bashrc login process in terminal.

When attempting to interact with a git repo using the secondary SSH key, access is denied.

The error from git is factual but not helpful:

> git pull
ERROR: Repository not found.
fatal: Could not read from remote repository.


Please make sure you have the correct access rights
and the repository exists.

The Fix

A reliable solution is to clear out all SSH keys from ssh-agent and re-add:

> ssh-add -D
> ssh-add -K ~/.ssh/customkeyname-id_rsa

Eventually I’ll troubleshoot the underlying issue but for now this fix is good enough.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s