How to Manage Multiple GitHub Accounts on the Same Laptop (Without Authentication Errors)

🛠️ Building modern web apps with React, Node.js, MongoDB & Express
If you are a developer like me, you probably have:
One personal GitHub account
One work GitHub account
Maybe another client account
And then one day… you try to push work code , But it gets pushed from your personal account.
Or worse:
Permission denied (publickey).
fatal: Could not read from remote repository.
I faced this exact problem.
Sometimes:
Code was pushing from the wrong account
Sometimes authentication failed
Sometimes GitHub was asking again and again for credentials
It became really frustrating.
So I researched properly, fixed it, and realized something important:
It is actually VERY simple. The issue happens because Git doesn’t know which account to use. The clean solution is using separate SSH keys.
Final Goal
After setup:
Personal repos → use personal account
Work repos → use work account
No login/logout
No authentication errors
No wrong commits
Step 1: Go to SSH Folder
Open Terminal.
Move to your SSH directory:
cd ~/.ssh
If the folder doesn’t exist, create it:
mkdir ~/.ssh
cd ~/.ssh
Step 2: Generate Separate SSH Keys for Each Account
Now we create different SSH keys.
For Personal GitHub Account
ssh-keygen -t ed25519 -C "your_personal_email@gmail.com"
When it asks:
Enter file_name in which to save the key:
Type:
id_personal
Press Enter.
🔹 For Work GitHub Account
Run again:
ssh-keygen -t ed25519 -C "your_work_email@company.com"
This time save as:
id_work
Now you have two different SSH keys.
Step 3: Add SSH Keys to SSH Agent
Start the SSH agent:
eval "$(ssh-agent -s)"
Add both keys:
ssh-add ~/.ssh/id_personal
ssh-add ~/.ssh/id_work
Step 4: Add SSH Keys to GitHub Accounts
Now go to:
👉 GitHub
For each account:
Go to Settings
Click SSH and GPG Keys
Click New SSH Key
Copy your public key:
cat ~/.ssh/id_personal.pub
Paste into Personal GitHub.
Then:
cat ~/.ssh/id_work.pub
Paste into Work GitHub.
Step 5: Configure SSH Config File (MOST IMPORTANT STEP)
Inside ~/.ssh folder create and edit config file:
nano ~/.ssh/config
Add this:
# Personal GitHub
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_personal
# Work GitHub
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_work
Save and exit.
This tells your laptop:
If repo uses github-personal → use personal key
If repo uses github-work → use work key
Step 6: Clone Repositories Properly
This is where most people make mistakes.
Wrong way:
git clone git@github.com:username/repo.git
Correct way:
For personal:
git clone git@github-personal:username/repo.git
For work:
git clone git@github-work:company/repo.git
That’s it.
Now Git knows which account to use.
Step 7: Set Git User Per Project
Inside each project folder:
Personal Project
git config user.name "Your Name"
git config user.email "your_personal_email@gmail.com"
Work Project
git config user.name "Your Name"
git config user.email "your_work_email@company.com"
Important: GitHub links commits based on email.
If email matches account → commit shows correctly.
Step 8: Test Your Setup
Run:
ssh -T git@github-personal
ssh -T git@github-work
If correct, it will say:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Why This Method Is Best
No repeated login
No password prompts
No authentication errors
Clean separation
Professional setup



