HB
Stories & Insights
Back to Blog

Managing Multiple GitHub Accounts on One Machine

July 05, 202515 min readBy Hemanth Babu S
gitgithubsshproductivitydeveloper-tools

Managing multiple GitHub accounts (like personal and work) on the same machine can be tricky if not set up properly. This guide walks you through setting up separate SSH keys, configuring Git, and switching seamlessly between accounts.


Alt text


✅ Prerequisites

Before diving in, make sure you have:

  • Git installed on your system (git --version)
  • A GitHub account (or two)
  • Basic knowledge of command line usage

🗝️ Step 1: Generate SSH Keys for Each Account

We'll generate separate SSH keys for your personal and work accounts.

Personal GitHub account

ssh-keygen -t rsa -b 4096 -C "you@example.com" -f ~/.ssh/id_rsa_personal

Work GitHub account

ssh-keygen -t rsa -b 4096 -C "you@work.com" -f ~/.ssh/id_rsa_work

This creates two key pairs:

  • ~/.ssh/id_rsa_personal & ~/.ssh/id_rsa_personal.pub
  • ~/.ssh/id_rsa_work & ~/.ssh/id_rsa_work.pub

🔗 Step 2: Add SSH Keys to GitHub

  1. Go to GitHub → SettingsSSH and GPG keysNew SSH key

  2. Add:

    • For personal: id_rsa_personal.pub
    • For work: id_rsa_work.pub
  3. Use a meaningful title for each key (e.g., “Personal Laptop”, “Work Laptop”).


🧼 Step 3: Adding SSH Keys to the SSH Agent

Run these commands in your terminal:

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa_personal
ssh-add ~/.ssh/id_rsa_work

Repeat these steps for each GitHub account, replacing file paths with the correct key names.


🛠️ Step 4: Create or Edit SSH Config

Open (or create) your SSH config file:

nano ~/.ssh/config

Add the following:

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

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

🧪 Step 5: Test SSH Connections

ssh -T git@github.com-personal
ssh -T git@github.com-work

You should see:

Hi <username>! You've successfully authenticated… for both.


📂 Step 6: Clone Repositories with Correct Host

When cloning, use the correct host alias:

# Personal repo
git clone git@github.com-personal:your-username/repo-name.git

# Work repo
git clone git@github.com-work:work-username/repo-name.git

🔧 Step 7: Set Git Identity Per Project

You can set identity per project:

cd ~/path/to/personal-repo
git config user.name "Your Name"
git config user.email "you@example.com"

cd ~/path/to/work-repo
git config user.name "Your Work Name"
git config user.email "you@work.com"


🧠 Conclusion

Managing multiple GitHub accounts on the same machine is totally doable with a little SSH and Git config magic. By separating your keys and using SSH aliases, you can avoid headaches and context-switch seamlessly.


Now you can:

✅ Work with both personal and professional repos
✅ Keep identities clean and separate
✅ Avoid constant re-authentication or mistakes

Hemanth Babu S

Author