In this post, I’m going to show you how to manage multiple GitHub accounts on mac with SSh keys. Add config file to make easy GitHub commands.
How to manage multiple GitHub accounts?
Watch the video and subscribe to my channel for more videos like this.
1 Create SSH keys for all accounts
cd ~/.ssh
ssh-keygen -t rsa -C "[email protected]" -f "github-personal"
ssh-keygen -t rsa -C "[email protected]" -f "github-work"
The -C option is a comment to help identify the key.
The -f option specifies the file name for the key pair.
You’ll now have a public and private key in your ~/.ssh/ folder.
2 Add the SSH keys to your SSH-agent
Your keys are now created but won’t be used until they are added to the agent. Let’s add them.
ssh-add -K ~/.ssh/github-personal
ssh-add -K ~/.ssh/github-work
You only need the -K option on a mac.
3 Add keys to your GitHub accounts
Copy the public keys and add them to the corresponding account.
pbcopy < ~/.ssh/github-personal.pub
pbcopy < ~/.ssh/github-work.pub
4 Create GitHub host entries for all accounts
Create the config file inside the ssh directory.
touch ~/.ssh/config
open -e ~/.ssh/config
Add each account you created earlier.
#personal account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/github-perosnal
#work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/github-work
Make one of your accounts global.
git config --global user.name "personal"
git config --global user.email "[email protected]"
Watch the video tutorial.