If you are using multiple github account for work and home projects or you are using one github account and one bitbucket account or any other git hosting service out there with SSH you have to manage SSH keys using a config file.
Lets go through each step for setting up github and bitbucket account-
Step 1: ssh keys
Create any keypairs you’ll need. In this example I’ve named these key pairs as ‘id_rsa_github’ and ‘id_rsa_’bitbucket:
ssh-keygen -t rsa -C “email@example.com" ssh-keygen -t rsa -C “firstname.lastname@example.org”
Step 2: ssh config
Set up multiple ssh profiles by creating/modifying ~/.ssh/config. Note the differing ‘Host’ values:
# For GitHub Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_github # For BitBucket Host bitbucket.org HostName bitbucket.org PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_bitbucket
Step 3: ssh-add
You may or may not have to do this. To check, list identity fingerprints by running:
$ ssh-add -l
2048 1f:1a:b8:69:cd:e3:ee:68:e1:c4:da:d8:96:7c:d0:6f email@example.com (RSA)
2048 6d:65:b9:3b:ff:9c:5a:54:1c:2f:6a:f7:44:03:84:3f firstname.lastname@example.org (RSA)
If your entries aren’t there then run:
ssh-add ~/.ssh/id_rsa_github ssh-add ~/.ssh/id_rsa_bitbucket
Step 4: test
To test you’ve done this all correctly, I suggest the following quick check:
$ ssh -T email@example.com
Hi Saurabh! You’ve successfully authenticated, but GitHub does not provide shell access.
I hope this will save someone’s hair!!