Managing Multiple GitHub/Git Accounts on One Machine (Personal + Work)

Table of contents
- Objectives
- Step 1: Generate Separate SSH Keys
- Step 2: Add Keys to SSH Agent
- Step 3: Configure SSH config File
- Step 4: Add Public Keys to GitHub
- Step 5: Clone Repositories Using SSH Host Aliases
- Step 6: Configure Git Identity per Repository
- Step 7: Enable Verified Commits with SSH Signing
- Step 8: Configure Git to Use Signing Keys
- Pre-Commit Workflow: Start SSH Agent and Test Connections
- Final Result
- The end! - Thanks for reading…

As developers and DevOps engineers, it's common to contribute to both personal and professional projects. However, using two GitHub accounts on a single machine can lead to identity conflicts
, unverified commits
, or accidentally pushing to the wrong repository
.
In this guide I’ll walks you through setting up two GitHub accounts securely, cleanly, and with verified SSH-signed commits all on a single machine.
Objectives
Work with both personal and work GitHub repositories (public & private).
Use two separate GitHub accounts on one machine.
Ensure verified commits via SSH commit signing.
Maintain a scalable, secure, and professional Git setup.
Step 1: Generate Separate SSH Keys
Create separate SSH key pairs for each GitHub account:
You can name these according to your preferences while generating the SSH keys
for-personal
for-work
# Personal Key
ssh-keygen -t ed25519 -C "you.email@gmail.com" -f ~/.ssh/for-personal
# Work Key
ssh-keygen -t ed25519 -C "you.workemail@gmail.com" -f ~/.ssh/for-work
Do not overwrite the default
id_ed25519
. Keeping keys separate ensures flexibility and security.
Step 2: Add Keys to SSH Agent
# View loaded keys
ssh-add -l
# Add new keys
ssh-add ~/.ssh/for-personal
ssh-add ~/.ssh/for-work
# Remove all existing keys (optional reset)
ssh-add -D
Step 3: Configure SSH config
File
Create or edit your SSH config file:
touch ~/.ssh/config
Add the following content:
# Global settings
Host *
AddKeysToAgent yes
UseKeychain yes
IdentitiesOnly yes
ServerAliveInterval 60
ServerAliveCountMax 3
# Personal GitHub
Host personal.github.com
HostName github.com
User git
IdentityFile ~/.ssh/for-personal
# Work GitHub
Host work.github.com
HostName github.com
User git
IdentityFile ~/.ssh/for-work
Step 4: Add Public Keys to GitHub
Upload the corresponding .pub
files to each account:
~/.ssh/for-personal.pub
→ Personal GitHub~/.ssh/for-work.pub
→ Work GitHub
GitHub → Settings → SSH and GPG Keys → New SSH Key
Step 5: Clone Repositories Using SSH Host Aliases
# Clone personal repo
git clone git@personal.github.com:your-username/my-repo.git
# Clone work repo
git clone git@work.github.com:my-org/work-repo.git
Step 6: Configure Git Identity per Repository
Set identity locally inside each project to avoid global conflicts:
# Inside Personal Repo
cd ~/PersonalRepo
git config user.name "your name"
git config user.email "your email"
# Inside Work Repo
cd ~/WorkRepo
git config user.name "your name"
git config user.email "your work email"
Step 7: Enable Verified Commits with SSH Signing
GitHub supports SSH-based commit signing, separate from SSH authentication.
Generate Signing Keys
# Personal Signing Key
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_signing_personal -C "signing-personal"
# Work Signing Key
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_signing_work -C "signing-work"
Add Signing Keys to GitHub
Go to GitHub → Settings → SSH and GPG Keys → New Signing Key and paste the contents of each .pub
file.
Step 8: Configure Git to Use Signing Keys
Set up commit signing in each repo:
# Personal Repo
cd ~/PersonalRepo
git config commit.gpgsign true
git config gpg.format ssh
git config user.signingkey ~/.ssh/id_ed25519_signing_personal.pub
# Work Repo
cd ~/WorkRepo
git config commit.gpgsign true
git config gpg.format ssh
git config user.signingkey ~/.ssh/id_ed25519_signing_work.pub
Pre-Commit Workflow: Start SSH Agent and Test Connections
Before making commits in any repository, ensure your SSH agent is running and keys are loaded:
# Ensure SSH agent is running and keys are loaded
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/personal_github
ssh-add ~/.ssh/work_github
# Test connections to verify which account will be used
ssh -T git@personal.github.com
# or
ssh -T git@work.github.com
# Now proceed with your git operations
git add .
git commit -m "Your commit message"
git push origin main
Successful messages like
Hi broh! You've successfully authenticated
confirm proper setup.
Note: This step is particularly important after system restarts or when opening new terminal sessions, as the SSH agent may not be running or may not have your keys loaded.
Final Result
Secure and clean GitHub SSH setup for both accounts.
Verified commits using SSH signing keys.
Separate identities per project.
Bonus Tip
To view signed commits:
git log --show-signature
The end! - Thanks for reading…
Subscribe to my newsletter
Read articles from Suraj directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Suraj
Suraj
I'm a Developer from India with a passion for DevOps ♾️ and open-source 🧑🏻💻. I'm always striving for the best code quality and seamless workflows. Currently, I'm exploring AI/ML and blockchain technologies. Alongside coding, I write Technical blogs at Hashnode, Dev.to & Medium 📝. In my free time, I love traveling, reading books