Skip to content

Instantly share code, notes, and snippets.

@ten0s ten0s/gen-deploykey
Last active Aug 18, 2016

Embed
What would you like to do?
Multiple Github Deploy keys on single machine
#!/bin/bash
# http://eclipsesource.com/blogs/2012/07/30/accessing-multiple-private-github-repositories-without-a-dedicated-build-user/
set -e
self=${0}
script_name=$(basename ${self})
script_dir=$(dirname ${self})
ssh_dir=${script_dir}/../common/ssh
if [[ $# < 1 ]]; then
echo "Generates repository Deploy key"
echo "https://developer.github.com/guides/managing-deploy-keys/#deploy-keys"
echo "Usage: ${script_name} <REPONAME>"
exit 1
fi
reponame=${1}
if [[ -f ${ssh_dir}/id_rsa-${reponame} ]]; then
echo "Deploy key for ${reponame} already exists"
exit 1
fi
ssh-keygen -t rsa -N "" -C "Deploy key for ${reponame}" \
-f ${ssh_dir}/id_rsa-${reponame}
cat >>${ssh_dir}/config <<EOF
Host ${reponame}.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa-${reponame}
EOF
echo
echo "Deploy key for ${reponame} generated."
echo "Now:"
echo "1. Go to ${reponame} -> Settings -> Deploy keys -> Add deploy key "
echo " and paste "
cat ${ssh_dir}/id_rsa-${reponame}.pub
echo "2. Run bin/images-build to rebuild the images"
echo "3. Push new images to the registry"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.