How to Add a Deploy Key to GitHub on Windows and Use Multiple Repositories
Learn to securely manage multiple GitHub deploy keys on Windows using Git Bash and SSH config. This tutorial covers key generation, GitHub setup, SSH configuration, and proper cloning.
Using deploy keys is a secure way to give a single machine access to one or more GitHub repositories. However, GitHub does not allow the same deploy key to be used across multiple repositories.
On Windows, you'll need to create a separate SSH key for each repository and use an SSH config file to distinguish between them.
This guide explains how to:
Generate SSH keys on Windows
Add deploy keys to GitHub
Configure SSH to use different keys for different repos
Clone using the correct host alias
1. Generate SSH Keys on Windows
Install Git Bash If you haven't already, download Git for Windows and install it. Open Git Bash to run the following commands.
Generate a New Key for the First Repo
ssh-keygen -t rsa -b 4096 -C "deploy-for-first-repo"
When asked where to save, press Enter to use the default (~/.ssh/id_rsa).
Generate a Second Key for Another Repo
ssh-keygen -t rsa -b 4096 -C "deploy-for-second-repo"
Enter a custom path like:
~/.ssh/id_rsa_second_repo
2. Add Deploy Keys to GitHub
Copy the Public Key
For the first repo:
cat ~/.ssh/id_rsa.pub
For the second repo:
cat ~/.ssh/id_rsa_second_repo.pub
Add to GitHub
Go to your repository on GitHub
Navigate to Settings > Deploy Keys
Click Add deploy key
Give it a name (e.g., "Windows Deploy Key")
Paste the public key
Click Add key
Repeat for each repo with its corresponding key.
3. Configure SSH to Use Different Keys
Create or edit your SSH config file:
vim ~/.ssh/config
Paste the following:
Host github-first
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-second
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_second_repo
Ensure correct permissions:
chmod 600 ~/.ssh/config
4. Clone Using Host Aliases
Wrong (will use default key):
git clone git@github.com:username/repo.git
Correct (uses custom config):
git clone git@github-first:username/repo1.git
git clone git@github-second:username/repo2.git
This tells SSH to use the correct key based on the host alias you defined.
✅ Summary
Use one deploy key per repo
Define each repo’s key in
~/.ssh/config
Clone using your custom Host alias
This way, you can use a single Windows system to securely access multiple private GitHub repositories with deploy keys.