A complete guide to set up and manage personal and work GitHub accounts on the same machine using SSH keys with automatic Git configuration.
- Linux/Mac
- Git installed
- Access to both GitHub accounts
- Terminal/command line knowledge
# Generate SSH key for personal account
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_personal
# Start SSH agent
eval "$(ssh-agent -s)"
# Add key to SSH agent
ssh-add ~/.ssh/id_ed25519_personal# Generate SSH key for work account
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_work
# Add key to SSH agent
ssh-add ~/.ssh/id_ed25519_workNote: When prompted for a passphrase, you can either:
- Add one for extra security (you'll need to enter it when using the key)
- Press Enter to skip (easier but less secure)
-
Copy the public key:
cat ~/.ssh/id_ed25519_personal.pub | pbcopy
-
Go to GitHub (personal account):
- Settings → SSH and GPG keys → New SSH key
- Title: "Personal Mac" (or any identifier)
- Paste the key and save
-
Copy the public key:
cat ~/.ssh/id_ed25519_work.pub | pbcopy
-
Go to GitHub (work account):
- Settings → SSH and GPG keys → New SSH key
- Title: "Work Mac" (or any identifier)
- Paste the key and save
Create or edit SSH config file:
nano ~/.ssh/configAdd the following configuration:
# Personal GitHub account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
# Work GitHub account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Important: The IdentitiesOnly yes ensures SSH only uses the specified key for each host.
Save and exit: Ctrl+X, then Y, then Enter
# Test personal account
ssh -T [email protected]
# Should show: Hi your-personal-username! You've successfully authenticated...
# Test work account
ssh -T git@github-work
# Should show: Hi your-work-username! You've successfully authenticated...If both show different usernames, you're all set! ✅
git config --global user.name "Your Name"
git config --global user.email "[email protected]"# Create a dedicated directory for all work projects
mkdir -p ~/WorkEdit global Git config:
nano ~/.gitconfigAdd this at the end of the file:
[includeIf "gitdir:~/Work/"]
path = ~/.gitconfig-work
Create work-specific config:
nano ~/.gitconfig-workAdd your work details:
[user]
name = Your Name
email = [email protected]
Clone normally from anywhere:
git clone [email protected]:your-username/repo-name.gitClone into the ~/Work directory using the github-work host:
cd ~/Work
git clone git@github-work:company/repo-name.gitKey differences:
- Personal:
[email protected]:username/repo.git - Work:
git@github-work:company/repo.git(note thegithub-workhost)
# List all SSH keys in agent
ssh-add -l# Check global config
git config --global --list
# Check config in a personal repo
cd ~/personal-repo
git config user.email # Should show personal email
# Check config in a work repo
cd ~/Work/work-repo
git config user.email # Should show work emailProblem: Both ssh -T commands show the same username
Solution: Make sure IdentitiesOnly yes is in your ~/.ssh/config and restart terminal
Problem: Can't authenticate with GitHub
Solutions:
# Check if keys are added to SSH agent
ssh-add -l
# If not, add them again
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
# Verify the key is added to GitHub accountProblem: Commits show wrong email address
Solution:
# Check current repo config
git config user.email
# If wrong, set it manually for this repo
git config user.email "[email protected]"
# Or move the repo to correct directory (~/Work for work repos)Problem: Permission denied or Repository not found
Solution: Make sure you're using the correct host
# Check remote URL
git remote -v
# If showing github.com instead of github-work, update it:
git remote set-url origin git@github-work:company/repo-name.git# Test SSH connections
ssh -T [email protected] # Personal
ssh -T git@github-work # Work
# Clone repositories
git clone [email protected]:user/repo.git # Personal
git clone git@github-work:company/repo.git # Work (in ~/Work)
# Check Git config
git config user.email # Check current repo
git config --global user.email # Check global
# View SSH keys
ssh-add -l # List loaded keys
ls -la ~/.ssh/ # List all SSH files
# Update remote URL (if needed)
git remote set-url origin git@github-work:company/repo.git~/
├── Work/ # All work projects (auto-uses work email)
│ ├── project-1/
│ ├── project-2/
│ └── project-3/
├── personal-project-1/ # Personal projects (uses personal email)
├── personal-project-2/
└── .ssh/
├── config # SSH configuration
├── id_ed25519_personal # Personal private key
├── id_ed25519_personal.pub # Personal public key
├── id_ed25519_work # Work private key
└── id_ed25519_work.pub # Work public key
- Always clone work repos into
~/Workdirectory - automatic email configuration - Use descriptive SSH key comments - helps identify keys later
- Test SSH connection before cloning - prevents authentication issues
- Keep SSH keys secure - never share private keys
- Verify commit author before pushing - run
git config user.emailto check - Use different key names - easier to manage and identify
- ✅ Add passphrases to SSH keys for extra security
- ✅ Never commit private keys (files without
.pubextension) - ✅ Regularly review SSH keys in GitHub settings
- ✅ Remove old/unused SSH keys from GitHub
- ✅ Use different SSH keys for different accounts (never reuse)
With this setup:
- ✅ Personal repos automatically use personal email
- ✅ Work repos (in
~/Work) automatically use work email - ✅ Each account uses its own SSH key
- ✅ No manual configuration needed per repository
- ✅ Clear separation between work and personal projects
If something doesn't work:
- SSH keys generated for both accounts?
- Public keys added to respective GitHub accounts?
-
~/.ssh/configfile created with correct configuration? -
IdentitiesOnly yespresent in SSH config? - SSH agent running and keys added?
- Tested SSH connection for both accounts?
-
~/.gitconfig-workfile created? - Work repos cloned into
~/Workdirectory? - Using correct host (
github-work) for work repos?
Feel free to suggest improvements or report issues!
MIT License - feel free to use and modify as needed.
Last Updated: 3rd December 2025