- You have two accounts with github
- You have git installed on your personal machine (currently comes pre-installed on a Macbook Pro)
Lets suppose you have two accounts on Github
On terminal:
ssh-keygen -t ed25519 -C "[email protected]" -f "id_ed25519_work"
Follow prompts for passprhase etc. (This will save private and public keys to ~/.ssh folder)
On terminal:
ssh-add ~/.ssh/id_ed25519_work
Make sure this is the private key and not the file ending in .pub
On web: github > profile avatar > settings > SSH and GPG Keys > New SSH Key
Give it a descriptive name - e.g. "Personal Macbook bought 2023"
Leave type as Authentication Key
On terminal:
cat ~/.ssh/id_ed25519_work.pub | pbcopy
(make sure this is the .pub file you are copying)
On web: paste into the Key field and press "Add SSH key"
e.g.
- instead of [email protected] use [email protected]
- instead of id_ed25519_work - use id_ed25519_personal
On terminal:
vim ~/.ssh/config
With contents:
Host work-github
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
Host personal-github
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
Instead of [email protected] use git@work-github or git@personal-github depending on which account you are using
e.g.
- Cloning:
git clone git@work-github:<organization>/<repositoryname>
- Adding new remote
git remote add origin git@personal-github:<username>/<repositoryname>
Once remote conection is established you shouldn't need to worrry about this again