Skip to content

Instantly share code, notes, and snippets.

@danikaze
Last active November 26, 2023 12:41
Show Gist options
  • Save danikaze/6965aca9673b19d06647f5324e0666f3 to your computer and use it in GitHub Desktop.
Save danikaze/6965aca9673b19d06647f5324e0666f3 to your computer and use it in GitHub Desktop.
Use multiple github repositories from the same server

1. Generate the ssh key:

ssh-keygen -t ed25519 -C "username@domain"

username@domain can be your email or the username @ server domain for easier readability, or anything.

Store it using a custom filename like ~/.ssh/github-REPO

2. Add the deployment key:

In your repository settings (https://github.com/USER/REPO/settings/keys), add a new key with the content from the public key (~/.ssh/github-REPO.pub)

3. Specify to use that key for that repo:

Edit ~/.ssh/config and add an entry like this:

Host github-REPO
  User git
  Hostname github.com
  IdentityFile /home/USRE/.ssh/github-REPO

Where the Host is what it's going to be used as the git origin URL, and the IdentityFile is the path for the key generated in the step 2

4. Set the origin for the repo using the custom domain

Go to the REPO folder and set it using

git remote set-url origin git@github-REPO:USER:REPO.git

It should work and each repo should be able to use its own ssh key to identify with github.

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