Deploy 2 GitHub repositories on the same server

This article shows the configuration to deploy 2 GitHub repositories on a single server.


On the Server

1) 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"

2) Push the private keys into the SSH Agent.

$ eval "$(ssh-agent -s)"
$ ssh-add key1
$ ssh-add key2

3) 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

4) Reload the SSH process.

$ sudo systemctl restart ssh

On Github

1) Add key1.pub to repo1.

2) Add key2.pub to repo2.


Deployment Script

1) 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'

AI Summary AI Summary
gpt-4.1-2025-04-14 2025-05-11 01:45:08
This article explains how to deploy two separate GitHub repositories on a single server by generating distinct SSH key pairs for each repository, configuring each with its own deploy key and SSH host setting, and updating deployment scripts to use the new repository URLs.
Chrome On-device AI 2025-05-24 11:57:28
Writing

Share Share this Post