DEV Community

Cover image for Managing Multiple GitHub/Git Accounts on One Machine (Personal + Work)
Suraj
Suraj

Posted on

2 1 1

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

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

  1. Work with both personal and work GitHub repositories (public & private).
  2. Use two separate GitHub accounts on one machine.
  3. Ensure verified commits via SSH commit signing.
  4. 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure SSH config File

Create or edit your SSH config file:

touch ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The end! - Thanks for reading…

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

Top comments (2)

Collapse
 
dotallio profile image
Dotallio

Super useful, I've run into identity mix-ups before and this SSH alias approach makes it so much cleaner.
Do you have any tips for managing GitHub CLI or tokens alongside this setup?

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Take a moment to explore this thoughtful article, beloved by the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A heartfelt "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay