[Git] Per Repo SSH Identity

Posted on in programming

cover image for article

For work, I need a personal GitHub account in addition to my Enterprise Managed User (EMU) account. After updating my SSH keys the other day, I realized I had inadvertently locked myself out of using my personal account on my work laptop.

Here's what that looked like:

$ 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.

What's happening here is that ssh is sending one of my work keys first, so GitHub happily authenticates me as my work account. EMUs don't have access outside of their enterprise, or really even understand there is an "outside", so we get the Repository not found error.

If you run into this (or any other git problem that seems SSH-related), you can force ssh to be more verbose like this: GIT_SSH_COMMAND="ssh -vvv" git fetch.

Based on one of the answers on StackOverflow, I ran this command in each of my personal GitHub account repos to make sure I was coming over as slaptijack:

git config core.sshCommand "ssh -i ~/.ssh/id_ed25519-slaptijack -o IdentitiesOnly=yes"

Since this doesn't have the --global flag, the change is only applied in that repo.

My Bookshelf

Reading Now

Other Stuff