This article shows the configuration to deploy 2 GitHub repositories on a single server.
On the Server
-
GitHub does not allow reusing the same deploy key in more than 1 repository. To cater for this restriction, we create a key pair for each repository.
$ ssh-keygen -t ed25519 -C "For repo1" $ ssh-keygen -t ed25519 -C "For repo2" -
Push the private keys into the SSH Agent.
$ eval "$(ssh-agent -s)" $ ssh-add key1 $ ssh-add key2 -
Create a new config file for SSH.
$ sudo pico /etc/ssh/ssh_config.d/my_repos.conf Host repo1 HostName github.com User git IdentityFile ~/.ssh/key1 Host repo2 HostName github.com User git IdentityFile ~/.ssh/key2 -
Reload the SSH process.
$ sudo systemctl restart ssh
On Github
-
Add key1.pub to repo1.
-
Add key2.pub to repo2.
Deployment Script
-
Update the repository URL in your deployment script. For example, in Capistrano:
(New) set :repo_url, 'git@repo1:username/myrepo1.git' set :repo_url, 'git@repo2:username/myrepo2.git' (Old) set :repo_url, 'git@github.com:username/myrepo1.git' set :repo_url, 'git@github.com:username/myrepo2.git'
Known Hosts
-
If you haven't been able to connect to the remote before, please remember to add it as your known host. E.g.
ssh -T git@github.com