How to Manage Multiple GitHub Accounts Using SSH
Learn how to use multiple GitHub accounts (personal and work) on the same machine using SSH without conflicts.
Joy Das
Managing multiple GitHub accounts (such as personal and work) on a single machine can be tricky. This guide walks you through a clean and professional way to handle multiple GitHub accounts using SSH keys—without switching accounts or facing permission issues.
Prerequisites
- Git installed (git --version)
- Terminal access (Linux/macOS) or Git Bash (Windows)
- Two GitHub accounts (personal & work)
1. Check Existing SSH Keys
ls ~/.sshLook for existing SSH keys like id_rsa, id_ed25519, or their .pub files. If none exist, continue to the next step.
2. Generate SSH Keys for Each Account
Generate a key for your personal GitHub account:
ssh-keygen -t ed25519 -C "your_personal_email@example.com"Generate a separate key for your work GitHub account:
ssh-keygen -t ed25519 -C "your_work_email@example.com" -f ~/.ssh/id_ed25519_work3. Add SSH Keys to SSH Agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add ~/.ssh/id_ed25519_work4. Add Public Keys to GitHub
Copy each public key and add it to the corresponding GitHub account under Settings → SSH and GPG keys.
cat ~/.ssh/id_ed25519.pub
cat ~/.ssh/id_ed25519_work.pub5. Configure SSH for Multiple Accounts
nano ~/.ssh/config# Personal GitHub Account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# Work GitHub Account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work6. Test SSH Connections
ssh -T git@github.com-personal
ssh -T git@github.com-work7. Clone Repositories Using Custom Host
git clone git@github.com-personal:yourusername/repo-name.git
git clone git@github.com-work:yourworkusername/work-repo.git8. Set Git User Info Per Repository
To avoid committing with the wrong identity, configure Git user info per repository.
git config user.name "Your Name"
git config user.email "your_email@example.com"Troubleshooting Tips
- Permission denied (publickey): Ensure SSH key is added and agent is running
- Wrong commit author: Check git config user.name and user.email
- SSH key ignored: Restart SSH agent and re-add keys
- GitHub not recognizing key: Make sure you added the public key, not private
Conclusion
With this SSH-based setup, you can seamlessly use multiple GitHub accounts on the same machine—no conflicts, no switching, and no headaches. This approach is ideal for developers managing both personal and professional projects.