setup multiple ssh for github
This usually happens when you use two ssh keys to access two different GitHub account.
Follow these steps to fix this it look too long but trust me it won't take more than 5 minutes:
Step-1: Create two ssh key pairs:
ssh-keygen -t rsa -C "[email protected]"
Step-2: It will create two ssh keys here:
~/.ssh/id_rsa_account1
~/.ssh/id_rsa_account2
Step-3: Now we need to add these keys:
ssh-add ~/.ssh/id_rsa_account2
ssh-add ~/.ssh/id_rsa_account1
You can see the added keys list by using this command: ssh-add -l
You can remove old cached keys by this command: ssh-add -D
Step-4: Modify the ssh config
cd ~/.ssh/
touch config
subl -a config or code config or nano config
Step-5: Add this to config file:
#Github account1
Host github.com-account1
HostName github.com
User account1
IdentityFile ~/.ssh/id_rsa_account1
#Github account2
Host github.com-account2
HostName github.com
User account2
IdentityFile ~/.ssh/id_rsa_account2
Step-6: Update your .git/config file:
Step-6.1: Navigate to account1's project and update host:
[remote "origin"]
url = [email protected]:account1/gfs.git
If you are invited by some other user in their git Repository. Then you need to update the host like this:
[remote "origin"]
url = [email protected]:invitedByUserName/gfs.git
Step-6.2: Navigate to account2's project and update host:
[remote "origin"]
url = [email protected]:account2/gfs.git
Step-7: Update user name and email for each repository separately if required this is not an amendatory step:
Navigate to account1 project and run these:
git config user.name "account1"
git config user.email "[email protected]"
Navigate to account2 project and run these:
git config user.name "account2"
git config user.email "[email protected]"