I have created two GitHub accounts. One for my work user and one for my personal self. I needed to do catch up on some work and as such cloned my work repo onto my personal PC. In order to do simple "git push origin master" commits without entering my username and password the whole time I simply want to add my public key from my home pc to the work repo. However Github gives this error:
Error: Key already use
After a bit of Googling I came across this link which states "To resolve the issue, remove the key from the other account or repository and add it to your account" Of course there is a duplicate key as I've added my home public key to github so that I can code on my own personal projects. After all I want to be able to code to my work repo using both my work pc and personal pc.
How can you add multiple "same" public keys without Github throwing that error and also why in the world, is that error thrown in the first place?
Open a terminal and use the ssh-keygen command with the -C flag to create a new SSH key pair. Replace the following: KEY_FILENAME : the name for your SSH key file. For example, a filename of my-ssh-key generates a private key file named my-ssh-key and a public key file named my-ssh-key.
You can create one more key pair, say id_rsa_personal.pub
, and add it to the Github account.
Next, create/edit the .ssh/config
file.
# Default GitHub Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa Host github-public HostName github.com User git IdentityFile ~/.ssh/id_rsa_public Host github-personal HostName github.com User git IdentityFile ~/.ssh/id_rsa_personal
The above file will help you to use more than one Github account. For background info, refer to the answers to this question.
Next, you will need to alter your .git/config
remote url to point to:
git@github-personal:<gh_username>/<gh_reponame>.git
Rather than the usual:
[email protected]:<gh_username>/<gh_reponame>.git
The key could be already in use on other github projects as deploy key, that's a bit tricky to find but run:
ssh -T -ai ~/.ssh/KEY_NAME [email protected]
change KEY_NAME
with the name of your SSH private key and you will be good to go
from: https://help.github.com/articles/error-key-already-in-use/#finding-where-the-key-has-been-used
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With