Besides my regular Github freethinker account, I had to create a new github account for my new job. Problem was how to manage different ssh keys for different github accounts as Github doesn’t allow the same key for more than one account. The Solution is:
1) Create a new alias for github.com in the ~/.ssh/config
file.
Host GitHub-readme Hostname=github.com IdentityFile=~/.ssh/id_rsa_alt
This alias still points to github.com but when you ssh into github using the new alias, it will use the alternative SSH key. It should be noted that Github recognizes you not by your username but by your ssh key.
Before you go on, do remember to ssh-add
the key.
ssh-add ~/.ssh/id_rsa_alt
To verify whether the ssh key has been added or not
ssh-add -l
2) Next, lets verify if our new configuration works with github. To do so, execute ssh -T git@GitHub-readme
, where GitHub-readme
is the new alias we created in step one with an alternative ssh key.
@~ $ ssh -T git@GitHub-readme Hi pratikreadmesys! You've successfully authenticated, but GitHub does not provide shell access.
3) Finally either clone a new repository or edit the .git/config
of your present repository. Use the new alias that we created in step 1 instead of ‘github.com’ in the command line.
git clone git@GitHub-readme:ReadmeSystemsInc/testrepository.git
Alternatively if you have already checked out the repository, update the remote URL.
[remote "origin"] url = git@GitHub-readme:ReadmeSystemsInc/testrepository.git fetch = +refs/heads/*:refs/remotes/origin/*