Last active
January 3, 2016 14:39
-
-
Save andergmartins/8478122 to your computer and use it in GitHub Desktop.
When using a CI server, like Jenkins, in conjunction with github, you may wish to use multiple deploy keys (github-speak for an rsa key pair that has been assigned to a single repo, rather than a user) to allow Jenkins to pull code from the github repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In the example here, where three repos are used, the idea is to take advantage of ssh's config mechanism | |
# For use with Jenkins, do the following: | |
# login to your CI Server | |
sudo su -s /bin/bash jenkins | |
cd ~/.ssh/ | |
# then create three key key pairs | |
ssh-keygen -f id_rsa_project1 | |
# on prompt, set target file to id_rsa_project1 | |
# repeat for id_rsa_project2 and id_rsa_project3 | |
# you should now have three key pairs: id_rsa_project1 id_rsa_project1.pub id_rsa_project2 id_rsa_project2.pub id_rsa_project3 id_rsa_project3.pub | |
# browse over to github and click on "admin" for each of the repo's, click on deploy key, and add deploy key | |
# copy over the .pub file contents for that repo's key pair | |
# repeat for all three repositories | |
# edit the ~/.ssh/config file | |
vim config | |
# enter contents like the following | |
Host project1.github.com | |
HostName github.com | |
User git | |
IdentityFile ~/.ssh/id_rsa_project1 | |
Host project2.github.com | |
HostName github.com | |
User git | |
IdentityFile ~/.ssh/id_rsa_project2 | |
Host project3.github.com | |
HostName github.com | |
User git | |
IdentityFile ~/.ssh/id_rsa_project3 | |
# now go into your Jenkins control panel | |
# in your jobs, alter the configs (or create) so that | |
# anywhere a github reference is made | |
# substitute akin to the following: | |
# project1.github.com:MyOrganization/Repo1.git | |
# | |
# this works great because ssh will lookup project1.github.com in the config file | |
# and substitute in the hostname and user, and use the correct private key file | |
# that corresponds to the deploy key on the repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment