Learn how to manage multiple GitHub accounts on the same machine using SSH keys and SSH config.
1. Generate a new SSH key for each GitHub account
# For personal account
ssh-keygen -t ed25519 -C "your-personal-email@example.com" -f ~/.ssh/id_ed25519_personal
# For work account
ssh-keygen -t ed25519 -C "your-work-email@example.com" -f ~/.ssh/id_ed25519_work
2. Add keys to the SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
3. Add public keys to GitHub
Go to GitHub → Settings → SSH and GPG Keys for each account and add:
cat ~/.ssh/id_ed25519_personal.pub
cat ~/.ssh/id_ed25519_work.pub
4. Create or edit SSH config
nano ~/.ssh/config # code ~/.ssh/config to open on vs code
Add this:
# Personal GitHub
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work GitHub
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
5. Use correct GitHub alias when cloning
# Personal repo
git clone git@github-personal:username/repo.git
# Work repo
git clone git@github-work:work-username/repo.git
6. Set Git identity per project
# Inside personal repo
git config user.name "Your Personal Name"
git config user.email "your-personal-email@example.com"
# Inside work repo
git config user.name "Your Work Name"
git config user.email "your-work-email@example.com"
You can now work with multiple GitHub accounts on the same machine without conflicts.
Top comments (0)