🚀 The Ultimate Guide to Setting Up GitHub SSH on Windows (Single & Multiple Accounts)

github-ssh-windows-single-multiple-accounts

Setting up GitHub SSH on Windows 11 doesn’t have to be painful. Whether you’re using Git Bash or PowerShell, working with one GitHub account or juggling multiple accounts (personal + office), this guide will get you set up with zero hassle.

We’ll cover single account quick start, multi-account setup, and all the real-world troubleshooting issues Windows developers usually face.

By the end, you’ll have a smooth Git + SSH workflow that just works. ✨

🏁 Quick Start: Single GitHub Account on Windows

If you’re only dealing with one account (most beginners do), follow this.

1. Install Git

  • Download & install Git for Windows.
  • This gives you Git Bash + Git itself.

Verify it works:

git --version
ssh -V

2. Configure Your Git Identity

This sets your name and email for commits.

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
git config --global --list

3. Generate SSH Key

Create your secure key pair:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Copy your public key and add it to GitHub:
GitHub → Settings → SSH and GPG keys → New SSH key

cat ~/.ssh/id_rsa.pub

4. Test Connection

ssh -T git@github.com

Expected:

Hi YOUR_USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

5. Clone Repos

Use SSH instead of HTTPS:

git clone git@github.com:your_username/your_repo.git

Or switch an existing repo:

git remote set-url origin git@github.com:your_username/your_repo.git
git remote -v

✅ Done! Single account SSH setup is ready.

👥 Multi-Account Setup: Personal + Work on Windows

Now, let’s say you have two accounts (personal + office). This is where things get tricky — but we’ll make it clean.

1. Generate Separate Keys

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

# Work
ssh-keygen -t rsa -b 4096 -C "work_email@example.com" -f ~/.ssh/id_rsa_work

Add both keys to the SSH agent:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_personal
ssh-add ~/.ssh/id_rsa_work

2. Create SSH Config File

This tells SSH which key belongs to which GitHub account.

Open the config file:

  • Git Bash:
  notepad ~/.ssh/config
  • PowerShell:
  notepad $env:USERPROFILE.sshconfig

Paste this:

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

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

💡 Save with LF line endings (not CRLF). In VS Code, bottom-right → change CRLF → LF.

3. Add Public Keys to GitHub

  • Personal:
  cat ~/.ssh/id_rsa_personal.pub

Add it in GitHub → Settings → SSH and GPG Keys.

  • Work:
  cat ~/.ssh/id_rsa_work.pub

Add to your work GitHub account.

4. Test Authentication

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

You should see a success message for both.

5. Clone Repositories with Correct Alias

  • Personal:
  git clone git@github.com-personal:username/repo.git
  • Work:
  git clone git@github.com-work:org/repo.git

6. Use Correct Identity Per Repo

Inside your work project folder, override the Git identity:

git config user.name "Work Dev"
git config user.email "work_email@example.com"

Now commits in this repo use your work email, while personal repos keep using the global one.

♻️ Automating SSH Agent on Windows

By default, Windows doesn’t remember keys after restart.
Fix this in Git Bash with ~/.bash_profile:

if [ -z "$SSH_AUTH_SOCK" ]; then
    eval "$(ssh-agent -s)"
fi

ssh-add -l | grep "id_rsa_personal" >/dev/null || ssh-add ~/.ssh/id_rsa_personal
ssh-add -l | grep "id_rsa_work" >/dev/null || ssh-add ~/.ssh/id_rsa_work

Now every new terminal session auto-loads your keys. 🎉

🛠️ Troubleshooting (Real-World Fixes)

1. Could not resolve hostname github.com-work

  • Cause: Wrong config file name (config.txt), CRLF endings, or alias mismatch.
  • Fix:
  mv ~/.ssh/config.txt ~/.ssh/config
  dos2unix ~/.ssh/config
  chmod 600 ~/.ssh/config
  ssh -T git@github.com-work

2. Permission denied (publickey)

  • Cause: Key not added, agent not running, or wrong identity.
  • Fix:
  eval "$(ssh-agent -s)"
  ssh-add -l
  ssh-add ~/.ssh/id_rsa_work
  ssh -vT git@github.com-work

3. Copy-pasting just the URL in PowerShell

❌ Wrong:

git@github.com-work:org/repo.git

✅ Correct:

git clone git@github.com-work:org/repo.git

4. Running ~/.ssh/config like a command

❌ Wrong:

~/.ssh/config

✅ Correct:

notepad ~/.ssh/config

5. Keys saved in wrong folder

If you didn’t specify ~/.ssh/ during keygen:

# Fix by moving
mv ~/id_work* ~/.ssh/
ssh-add ~/.ssh/id_work

🧭 PowerShell vs Git Bash: What’s Different?

  • Both can run git clone, git pull, git push.
  • Path differences:

    • Git Bash → /c/Users/<username>/
    • PowerShell → C:Users<username>
  • Editing config:

    • Git Bash → notepad ~/.ssh/config
    • PowerShell → notepad $env:USERPROFILE.sshconfig

📋 Cheat Sheet (Copy, Paste, Go)

Identity

git config --global user.name "Your Name"
git config --global user.email "you@personal.com"
git config user.name "Work Dev"     # inside work repo
git config user.email "work@company.com"

Keys

ssh-keygen -t rsa -b 4096 -C "email" -f ~/.ssh/id_rsa_label
ssh-add ~/.ssh/id_rsa_label

SSH Config

Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_personal

Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_work

Clone

git clone git@github.com-personal:username/repo.git
git clone git@github.com-work:org/repo.git

🎯 Final Thoughts

Setting up GitHub SSH on Windows 11 can be messy if you’re not careful — especially with multiple accounts. But with:

  • Global config for personal
  • Per-project config for work
  • SSH aliases for clarity
  • Agent automation

… you’ll have a rock-solid workflow across Git Bash and PowerShell.

So whether you’re pushing to your personal side projects or your office repos, you can switch identities seamlessly — no more errors, no more headaches. 🚀

🔥 What about you? Do you manage multiple GitHub accounts on the same machine?
Drop your tricks in the comments below — let’s share some dev wisdom!