
A step-by-step guide to seamlessly manage multiple GitHub accounts with SSH keys.
Managing Multiple GitHub Accounts on One Machine Using SSH
If you use both personal and work GitHub accounts on the same machine, authentication issues are almost inevitable. Commits go to the wrong account, pushes fail, or Git keeps asking for credentials.
The clean solution is simple: one SSH key per account, configured once, and reused forever. This guide shows how to do exactly that.
What You’ll Learn
- Create separate SSH keys for each GitHub account
- Configure SSH to automatically select the correct identity
- Clone, push, and commit without account conflicts
Applies to: macOS and Linux (Windows users via WSL or Git Bash can follow the same steps)
Prerequisites
- Git installed
- Basic terminal knowledge
- Access to multiple GitHub accounts
Step 1: Generate a Dedicated SSH Key
Create a new key for your work account:
ssh-keygen -t ed25519 -C "work@email.com" -f ~/.ssh/id_ed25519_work
This avoids overwriting existing keys and clearly separates identities.
When prompted, adding a passphrase is recommended for security.
Generated files:
- id_ed25519_work — private key (keep secret)
- id_ed25519_work.pub — public key (add to GitHub)
Step 2: Add the Key to the SSH Agent
Start the agent and load your key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_work
This allows Git to authenticate without repeatedly asking for a passphrase.
Step 3: Add the Public Key to GitHub
Copy your public key:
cat ~/.ssh/id_ed25519_work.pub
Copy the entire output (starts with ssh-ed25519).
- Navigate to: https://github.com/settings/keys
- Click New SSH key
- Add a title (e.g., “Work Laptop — 2024”)
- Paste your public key
- Click Add SSH key

Highlighting where to add your SSH key in GitHub settings.
Step 4: Configure SSH Host Aliases
Edit your SSH config:
nano ~/.ssh/config
Add:
# Here you can add multiple identities personal, work etc.
# Personal account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
# Work account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
This tells SSH exactly which key to use for each account.
Step 5: Test the Setup
ssh -T github-work
If successful, GitHub will confirm authentication. Expected output:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Using the Correct Account
Clone Repositories
# Work account
git clone git@github-work:company/repo.git
# Personal account
git clone git@github.com:username/repo.git
Fix an Existing Repository
git remote set-url origin git@github-work:company/repo.git
Set Commit Identity (Per Repository)
git config user.name "Your Name"
git config user.email "work@company.com"
This ensures commits are attributed correctly.
Final Thoughts
Managing multiple GitHub accounts doesn’t require hacks or workarounds.
With one SSH key per account and a clear SSH configuration , Git becomes invisible — and that’s exactly how tooling should behave.
Configure it once. Forget about it forever.
Top comments (0)