How to Use GitHub with Multiple Users on One Machine

Working with multiple GitHub accounts on a single machine—such as one for work and another for personal projects—can be tricky. But with the right configuration of SSH keys and Git settings, it’s entirely manageable.

In this guide, you’ll learn how to set up and use multiple GitHub accounts (users) on the same system.


✅ Step 1: Generate Separate SSH Keys for Each GitHub Account

Start by generating a unique SSH key for each GitHub account.

🔹 For Personal Account:

ssh-keygen -t ed25519 -C "yo*@pe******.com"

Save as:

~/.ssh/id_ed25519_personal

🔹 For Work Account:

ssh-keygen -t ed25519 -C "yo*@wo**.com"

Save as:

~/.ssh/id_ed25519_work

✅ Step 2: Add SSH Keys to the SSH Agent

Start the SSH agent:

eval "$(ssh-agent -s)"

Add both keys:

ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work

✅ Step 3: Add SSH Keys to GitHub Accounts

  1. Copy the public key to your clipboard:
cat ~/.ssh/id_ed25519_personal.pub
  1. Go to your GitHub Settings > SSH and GPG keys
  2. Click New SSH Key, paste the key, and name it accordingly

Repeat for the work account using its respective public key.


✅ Step 4: Create SSH Config File

Edit or create the SSH config file:

nano ~/.ssh/config

Add the following:

# Personal GitHub
Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_personal

# Work GitHub
Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work

✅ Step 5: Clone Repositories with Custom Hosts

Use the custom Host from your SSH config when cloning:

# Personal
git clone gi*@gi****.com-personal:your-username/repo.git

# Work
git clone gi*@gi****.com-work:your-work-username/repo.git

✅ Step 6: Set Per-Repository Git Config (Optional)

Set user info per repository:

cd my-repo
git config user.name "Your Name"
git config user.email "yo*@pe******.com"

Or for work:

git config user.name "Your Work Name"
git config user.email "yo*@wo**.com"

✅ Bonus: Use Environment Variables (Optional)

For scripting or automation, you can also switch credentials by setting environment variables or using credential helpers, especially if using HTTPS instead of SSH.


✅ Summary

TaskCommand / Action
Generate SSH keysssh-keygen -t ed25519 -C "email"
Add to SSH agentssh-add ~/.ssh/id_ed25519_*
Update ~/.ssh/configDefine custom Host entries
Clone with correct Hostgit clone gi*@gi****.com-work:org/repo.git
Set local Git user/emailgit config user.name/email in each repo

🚀 Final Thoughts

Using multiple GitHub accounts on one system is all about managing SSH keys and per-repository settings. With a well-organized setup, you can seamlessly switch between personal and professional projects without logging in and out of GitHub.

Sharing Is Caring:

Leave a Comment