How to use multiple github accounts on Mac
2024-09-06 01:21:42
we may need multiple github accounts in our daily work, so I want to introduce a easy way to config multiple accounts on our Mac machine.
Create SSH keys for all accounts
First make sure your current directory is your .ssh folder.
1 | cd ~/.ssh |
Syntax for generating unique ssh key for ann account is:
1 | ssh-keygen -t rsa -C "your-email-address" -f "github-username" |
here
-C: stands for comment to help identify your ssh key
-f: stands for the file name where your ssh key get saved
1 | ssh-keygen -t rsa -C "hippiezhou@gmail.com" -f "github-work" |
Add SSH public key to the Github
Copy the public key
1 | vim ~/.ssh/github-work.pub |
Paste the public key on Github
- Sign in to Github Account
- Goto Settings > SSH and GPG keys > New SSH Key
- Paste your copied public key and give it a Title of your choice.
Add SSH keys to SSH Agent
add some alias in ~/.zshrc
file
1 | alias ssh-personal="ssh-add -D && ssh-add ~/.ssh/github-personal && git config --global user.name 'happy life' && git config --global user.email 'hippiezhou@outlook.com'" |
Then you can use a CLI alias to switch to the account that you want.
1 | # switch to personl account |
More info: ssh-agent