sethserver.com Subscribe
Laptop computer surrounded by colorful security keys representing technical SEO optimization, website coding, and digital marketing strategies on cloud background

Secure GitHub Deployments: Using Multiple SSH Keys for Repositories

By Seth Black • Updated: December 22, 2025

Programming · 4 min read

Like this kind of writing? Get one email a week with notes on startups, AI, and the occasional strong opinion about Python: subscribe to the newsletter.

GitHub does not like using the same deploy key across multiple repositories. Try it, you'll get a really fun "Key is already in use" error in a lovely pink box at the top of your screen. What if we have multiple repositories residing on one server? How do we pull from different repositories using the same user? We use a whole bunch of SSH keys, of course!

Git version 2.3.0 introduced an amazing environment variable named GIT_SSH_COMMAND which, very conveniently, allows us to override the default SSH command. This new variable give us the freedom to do a whole bunch of fancy SSH stuff, such as specify a different SSH key for a git pull. Let's check it out.

We'll assume you have two repositories up on GitHub called github.com:current-startup/node-app and github.com:current-startup/legacy-node that you'd like to deploy to the server prod01 (prod02 crashed the other day and we haven't been able to get it back up #startuplife). We'll also assume that you're using git over SSH and not over HTTP.

Your typical workflow (assuming everything worked the way you expected without the key in use error) would be to:

  1. push your code to master
  2. SSH into prod01
  3. cd into node-app
  4. git pull origin master
  5. restart node-app service
  6. cd into legacy-node
  7. git pull origin master
  8. restart legacy-node service
  9. exit prod01

Unfortunately, node-app and legacy-node both run under the same web user (I don't know why it was done this way. Isolation is so much better! Someone will get around to fixing this someday; but, again #startuplife). This is where we run into our SSH key issue. Here's our fix:

Create an SSH key for each app.

web@prod01:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/web/.ssh/id\_rsa): /home/web/.ssh/id\_rsa\_node\_app
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/web/.ssh/id\_rsa\_node\_app.
Your public key has been saved in /home/web/.ssh/id\_rsa\_node\_app.pub.
The key fingerprint is:
SHA256:[stuff] web@prod01
The key's randomart image is:
+---[RSA 2048]----+
| \* \*\* |
[stuff]
| c++ |
+----[SHA256]-----+
web@prod01:~$ cat .ssh/id\_rsa\_node\_app.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAA...
[stuff]
...YFbPa5bA1FVHDmch/l1/tvXaNVymkiEN web@prod01
web@prod01:~$
web@prod01:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/web/.ssh/id\_rsa): /home/web/.ssh/id\_rsa\_legacy\_node
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/web/.ssh/id\_rsa\_legacy\_node.
Your public key has been saved in /home/web/.ssh/id\_rsa\_legacy\_node.pub.
The key fingerprint is:
SHA256:[stuff] web@prod01
The key's randomart image is:
+---[RSA 2048]----+
| -- |
[stuff]
| \*+. |
+----[SHA256]-----+
web@prod01:~$ cat .ssh/id\_rsa\_legacy\_node.pub
ssh-rsa AAAAB3NsiflsAA8dfjQQdflkABAA...
[stuff]
...ZFdQa8qD2lLSKDJFl1/LXKJIDFljsdfiL web@prod01
web@prod01:~$

Take the .pub files that I so conveniently cat'd out for you and save them as deploy keys in GitHub (Settings -> Deploy keys -> Add deploy key). You should copy-paste them directly from the terminal and not try to type them in. Begin copying at the line that begins with "ssh-rsa" and stop at the line with user@hostname (in this example web@prod01).

Each key should go into its respective repository. In this example the key id_rsa_node_app.pub should be added to github.com:current-startup/node-app deploy keys and id_rsa_legacy_node.pub should be added to github.com:current-startup/legacy-node deploy keys.

Now, we can use GIT_SSH_COMMAND to tell git to use our new SSH keys instead of the default SSH key.

web@prod01:~$ cd ~/node-app
web@prod01:node-app$ GIT\_SSH\_COMMAND='ssh -i /home/web/.ssh/id\_rsa\_node\_app' git pull origin master
remote: Counting objects: 5, done.
remote: Total 5 (delta 4), reused 5 (delta 4), pack-reused 0
[stuff]
7 files changed, 213 insertions(+), 45 deletion(-)
web@prod01:node-app$ service node-app restart
**OK**
web@prod01:node-app$ cd ~/legacy-node
web@prod01:legacy-node$ GIT\_SSH\_COMMAND='ssh -i /home/web/.ssh/id\_rsa\_legacy\_node' git pull origin master
remote: Counting objects: 5, done.
remote: Total 5 (delta 4), reused 5 (delta 4), pack-reused 0
[stuff]
7 files changed, 213 insertions(+), 45 deletion(-)
web@prod01:legacy-node$ service legacy-node restart
**OK**

There you have it. Not the most beautiful solution ever, but definitely something I've run into enough times that I felt the need to write about it! Happy coding!

-Sethers

Share this post
Newsletter

One email, once a week.

Notes on databases, systems, and the occasional strong opinion about Python. No spam, unsubscribe anytime.

Seth Black
Written by

Seth Black

Engineer and founder based in Texas. Writes about databases, AI, and running things in production. Embeds in small teams as lead engineer.

More from Programming

View all →
Programming

What's the Differences Between Relational, NoSQL, Vectors, and Caches

Apr 14, 2026
Programming

Git and Source Control in AI Land

Apr 14, 2026
Programming

Domains, DNS, and why it feels fragile

Apr 14, 2026