There are several blogs that outlines how to have multiple SSH certs with different github accounts and yet I had to google around after trying out a couple of them to figure out the right settings. If you're wondering how to do this, follow along. Also meant as note-to-self.
Create a new SSH key pair
$ ssh-keygen -t rsa -C "your-email@domain.com"
Here for the email address I gave the email address generated by github that mask your real email address.
This create a private and public keypair in ~/.ssh. id_rsa
and id_rsa.pub
. Rename this to reflect the github account name. Not necessary but to keep things organized when you're working with multiple github accounts.
~/.ssh/id_rsa_wxyz
~/.ssh/id_rsa_wxyz.pub
Add the keys
$ ssh-add ~/.ssh/id_rsa_wxyz
Check saved keys
$ ssh-add -l
Configure SSH
Edit ~/.ssh/config
,
Host github.com-wxyz
HostName ssh.github.com
Port 443
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_wxyz
This is where some blogs are not updated. I had to add ssh in front of github on the HostName param. Then the respective port. Otherwise it was trying to connect to port 22 and timing out.
Checking out repo
When checking out github repo, the URL should reflect the Host portion followed by the github ID and the repo name.
git clone git@github.com-wxyz:wx-yz/ballerina-lang.git
Set username and email
After cloning the repo, you might want to modify the username and email for the local repo. This is useful if you like to have different IDs/email combos for different repos. If you have one username/email combo for all your repos you probably have this as a global config
$ git config user.name "wx-yz"
$ git config user.email "<insert autogenerated email from github"
Top comments (0)