Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to configure multiple deploy keys for different private github repositories on the same computer

This is probably a common issue for people who wants to deploy serveral repository on one VPS or VM.

This is not going to be rocket science.

The first step is to generate your first ssh key, for this type the following command line in your terminal: ssh-keygen -t rsa -b 4096 -C "" When the command CLI is asking you if you want to use a passphrase you might want to press ENTER in order to don't have to type it everytime you will want to pull your repository.

Now copy the content of your public key and add it to Github in your first repository (Settings > Deploy keys). For example on debian it might be: cat /home/debian/.ssh/

Now we can clone our repository via ssh with the following command: git clone

The next step is to rename our ssh keys and configure them.

To do this you need to go to the following folder: ~/.ssh by typing: cd ~/.ssh. And now rename your keys:

mv id_rsa id_repo1_rsa

Now we need to configure our keys in the repo and ssh, to do this type the following command line:

nano ~/.ssh/config

And add the following content:

Host repo1
  User git
  IdentityFile ~/.ssh/id_repo1_rsa
  IdentitiesOnly yes

In our git folder open the git config and edit like this:

nano .git/config
[remote "origin"]
#	url =
	url = "ssh://git@repo1/YourGitHubName/repo1.git"

Congratulation you can now test by typing: git pull origin master and see that our conifguration is working.

Now you can repeat the following steps for your other repositories and start by generating a new ssh key to use as a deploy key in another repository.

Copy link

Worked for me. Thanks :)

Copy link

Thanks for your help.

Copy link

egerb commented Sep 4, 2022

it's more clear now, thank you a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment