How to set GitHub SSH key for a particular repo

2 min readJan 5, 2023

I often have multiple GitHub accounts on a single computer, for a range of different reasons; personal account, side project accounts, work accounts etc. and I often run into the issue of having access denied when trying to clone or push commits.

After I had followed all the instructions here to add multiple ssh keys to my system and tested them I was still getting access denied errors on my GitHub repos that were not my work ones.

After spending FAR too long Googing this issue and getting nowhere I found this Stack Overflow answer: I tried adding -config core.sshCommand=”ssh -i ~/location/to/private_ssh_key” to the end of my git clone command, and it worked! I was able to clone my personal GitHub repos.

Now I still had the issue of pushing commits to that repo, I was still getting the following error: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Even after trying to add the same --config to the git push command I was getting that error, I thought I was stuck again. Then I realized that it must be a git config setting, and found it

Finally, ran:

git config core.sshCommand "ssh -i ~/.ssh/[PERSONAL_KEY] -F /dev/null"

And I was able to push my commits.

However, after pushing my changes I found that I was still pushing as my work user, so my commits were being signed as my work GitHub account, not exactly what I wanted. But this is an easy fix too, just run:


Now all of your commits will be signed as the right user too!

Originally published at on January 5, 2023.




A collection of my learnings in all things Python, AI, MLOPS, NLP, Software engineering, and Bug Bounty Hunting.