Member-only story
How To Connect To Two Github.com Repos Using Different SSH keys
Often you have a use-case where you have 2 different Github.com user accounts, say one for personal projects and another for work.
From the same machine you would like to clone repositories belonging to the 2 different GitHub.com userids, and using 2 different SSH keys.
How do you achieve that?
We’ll use something called host aliases in SSH Config.
Step 1 — Generate SSH Keys
You first generate the SSH keys for the 1st user like so:
ssh-keygen -t ed25519 -C "user1@somedomain.com" -f ~/.ssh/id_ed25519_user1
Then you generate the SSH key for the 2nd user like so:
ssh-keygen -t ed25519 -C "user2@someotherdomain.com" -f ~/.ssh/id_ed25519_user2
Step 2 — Upload the private keys into GitHub
For each of the 2 accounts in GitHub.com, upload your individual Private SSH key in the account settings.