Setup different deploy keys for different GitHub repositories
We want to allow a foreign machine to read and write to a GitHub repository. We will use a GitHub "deploy" key to accomplish this. This process allows you to use different key-pairs for different GitHub repositoies in the same GitHub account.
Say you have two projects project1
and project2
in your GitHub
account. You can set up the same deploy key for both projects or different
keys for each.
We assume that the GitHub repository is called
project9
.Create a new SSH key-pair. For the e-mail address you can put anything you want; it is just a label.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f project9
The above comand created two files:
project9
(containing the private part of of the key-pair) andproject9.pub
(containing the public part).Move these two files into your usual
.ssh
directory where all your SSH options and other keyfiles are kept. For example:mv project9* $HOME/.ssh/
Add the public key (
project9
) as a deploy key in the GitHub repositoryproject
. Be sure to CHECK the "Allow write access" box.Clone the GitHub repository:
git clone https://github.com/githubuser/project9.git
Change directory into the cloned repository:
cd project9
Configure this working directory to use the
project9
SSH private key when pushing:git config core.sshCommand "ssh -i ~/.ssh/project9 -F /dev/null"
Change the URL from
https
tossh
:git remote set-url origin git@github.com:githubuser/project9.git
Now you can push.