BETA

Command Palette

Search for a command to run...

Git & DevOps7 min read

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.

JD

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

bash
ls ~/.ssh

Look 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:

bash
ssh-keygen -t ed25519 -C "your_personal_email@example.com"

Generate a separate key for your work GitHub account:

bash
ssh-keygen -t ed25519 -C "your_work_email@example.com" -f ~/.ssh/id_ed25519_work

3. Add SSH Keys to SSH Agent

bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add ~/.ssh/id_ed25519_work

4. Add Public Keys to GitHub

Copy each public key and add it to the corresponding GitHub account under Settings → SSH and GPG keys.

bash
cat ~/.ssh/id_ed25519.pub
cat ~/.ssh/id_ed25519_work.pub

5. Configure SSH for Multiple Accounts

bash
nano ~/.ssh/config
text
# 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_work

6. Test SSH Connections

bash
ssh -T git@github.com-personal
ssh -T git@github.com-work

7. Clone Repositories Using Custom Host

bash
git clone git@github.com-personal:yourusername/repo-name.git
git clone git@github.com-work:yourworkusername/work-repo.git

8. Set Git User Info Per Repository

To avoid committing with the wrong identity, configure Git user info per repository.

bash
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.