Multiple private keys with git
Github can’t add one ssh private key on multiple accounts. Therefore, I figure out what can I do with multiple private keys. Someone already answered this on SO. But, I take a note on the blog to remember and easier for my use case.
I want to use one private key on multiple Github accounts. Github does not allow it. The reason why I want to do this is, that I have two Github accounts. One for the office and one for the personal. Sometimes, I want to push some stuff to my own Github account. In this case, can not.
Use two different key pairs and configure with ssh config. Just like the following…
~/.ssh/config # Default GitHub Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa Host github-personal HostName github.com User git IdentityFile ~/.ssh/id_rsa_personal
As per the config, the default one will be
~/.ssh/id_rsa. You don’t need to do anything to use the default one. But, if you want to use a personal one, you have to set the remote URL of the repo to something like the following…
git remote set-url origin github-personal:setkyar/repo-name.git
That’s it. Short note for my future self.