When working with Github. Setting up SSH key based authentication is easy. You just create a key. Add the public key in the admin panel and voilà. If a new contributor joins your team. You add his / her key and they also have access.
But how does it work when you have need access to multiple repositories using multiple keys yourself? I had to set this up a couple of times. And it turns out to be just as easy. But if for some reason it’s not that obvious these steps might help.
Let’s pretend we need some key first.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): repo1_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in repo1_rsa.
Your public key has been saved in repo1_rsa.pub.
The key fingerprint is:
The key’s randomart image is:
+–[ RSA 4096]—-+
This will generate the public and private key for repo1. Now repeat the same thing for repo2. Make sure the keys reside in ~/.ssh
Now let’s say we have access to two repositories under two different users / companies. We will use github.com/repo1 and github.com/repo2 as examples. The only thing we have to do is add some entries to ~/.ssh/config to make this work. They key is to use the Github sub-domain mappings
Save the file and we’re done. Now to checkout a project in one of the repositories. Do the following.
Cloning into ‘project’…
remote: Counting objects: 86, done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 86 (delta 27), reused 64 (delta 17)
Receiving objects: 100% (86/86), 34.83 KiB, done.
Resolving deltas: 100% (27/27), done.