Skip to content

Instantly share code, notes, and snippets.

@tanhaa
Created October 5, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanhaa/768e174140da1b5144629c2d627fcf63 to your computer and use it in GitHub Desktop.
Save tanhaa/768e174140da1b5144629c2d627fcf63 to your computer and use it in GitHub Desktop.
Multiple Git repos with multiple deploy ssh keys
repo1:  github.com:myOrg/repo1.git
repo2:  github.com:myOrg/repo2.git

Create two SSH Keys. Follow: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

key1:  repo1_id_rsa
key2:  repo2_id_rsa

Add keys:

eval `ssh-agent`
ssh-add ~/.ssh/repo1_id_rsa
ssh-add ~/.ssh/repo2_id_rsa

Make new file in ~/.ssh vim config

Host repo1.github.com
  HostName github.com
  User git
  IdentityFile /home/myUser/.ssh/repo1_id_rsa
  IdentitiesOnly yes

Host repo2.github.com
  HostName github.com
  User git
  IdentityFile /home/myUser/.ssh/repo2_id_rsa
  IdentitiesOnly yes

Now you can git clone your repositories:

git clone repo1.github.com:myOrg/repo1.git
git clone repo2.github.com:myOrg/repo2.git

If the repositories are already cloned, edit your origin uri to the above uri by either editing the repo1/.git/config file and then simply modifying the origin uri by adding repo1 or repo2 in front of github.com in git@github.com part. Or remove the origin by using git remote rm origin and add a new origin with the above uri by doing git remote add origin <uri>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment