Git SSH Key(s) Problem


tags: ssh git

I have two keys for a corporate github repo: my own (under which I also manage my own repos on github) and a read-only one we keep around for developers/managers that need it. I occasionally load the read-only one into the ssh agent, and every time I do I regret it:

$ git push origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

git remote -v shows that origin is set correctly. Worse, git pull origin master will work just fine (it's a read-only key, it can do that), which makes finding the error more difficult. Sometimes you can have both loaded into memory, and yet a git push will work - intermittent problems are a real joy. This last is because ssh apparently offers the ssh keys to the remote host in the order they're loaded into memory, so if the read-write key was loaded first and the read-only was loaded last, a push will work.

The solution is to run ssh-add -l to find out what keys are in the ssh-agent (it's the agent that holds them, but the command goes to ssh-add - go figure) and then deleting the offending key from the agent with ssh-add -d ~/.ssh/badkey_dsa .