---
title: Deploy 2 GitHub repositories on the same server
url: https://calvin.my/posts/deploy-2-github-repositories-on-the-same-server
published: 2025-05-04
updated: 2026-09-17
category: Operations
tags:
- GitHub
- Deploy
- SSH
- Rails
- Capistrano
summary: The post explains how to deploy two GitHub repositories from one server despite GitHub’s restriction on sharing a deploy key across repositories. It recommends generating separate SSH key pairs, loading them into the SSH agent, and defining host aliases that map each repository to its own identity file. After adding each public key to the matching GitHub repository, deployment scripts should use the aliases, with GitHub added to known hosts if needed.
---

# 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.&nbsp;

   ```bash
   $ ssh-keygen -t ed25519 -C "For repo1"
   $ ssh-keygen -t ed25519 -C "For repo2"
   ```

2. Push the private keys into the SSH Agent.

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

3. Create a new config file for SSH.

   ```bash
   $ 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.

   ```bash
   $ 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:

   ```ruby
   (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

1. If you haven't been able to connect to the remote before, please remember to add it as your known host. E.g.

   ```bash
   ssh -T git@github.com
   ```
