DEV Community

Muhammad Aqib Bin Azam
Muhammad Aqib Bin Azam

Posted on

1

πŸ” How to Connect Multiple GitHub Accounts via SSH in VS Code (Personal + Work Setup)

If you're juggling multiple GitHub accounts β€” like a personal and a work account β€” and using VS Code as your primary editor, setting up SSH correctly will save you tons of authentication headaches.

In this guide, you'll learn how to connect GitHub via SSH in VS Code using multiple profiles so you can push, pull, and clone from different GitHub accounts seamlessly.


🧠 Why Use SSH with GitHub in VS Code?

Using SSH instead of HTTPS allows you to:

  • Avoid entering credentials or PATs every time
  • Manage personal and work GitHub accounts side-by-side
  • Enable smooth Git integration inside Visual Studio Code
  • Easily switch between multiple profiles using SSH config

Step 1: Generate SSH Keys for Personal and Work GitHub Accounts

Open your terminal inside VS Code and run:

πŸ” For personal GitHub:

ssh-keygen -t ed25519 -C "yourpersonal@email.com" -f ~/.ssh/id_ed25519_personal
Enter fullscreen mode Exit fullscreen mode

πŸ” For work GitHub:

ssh-keygen -t ed25519 -C "yourwork@email.com" -f ~/.ssh/id_ed25519_work
Enter fullscreen mode Exit fullscreen mode

This creates two key pairs, one for each account.


πŸ”‘ Step 2: Add SSH Keys to SSH Agent in VS Code Terminal

Start the SSH agent:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Add both keys:

ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
Enter fullscreen mode Exit fullscreen mode

This ensures VS Code and Git can use these keys for SSH authentication.


🧩 Step 3: Configure SSH Profiles for VS Code in ~/.ssh/config

Open or create your SSH config file from VS Code:

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

Add this:

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

# Work GitHub
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

πŸ” This tells Git and VS Code which key to use for which GitHub host.


πŸ—οΈ Step 4: Add Public Keys to GitHub

Use these commands to get your public keys:

cat ~/.ssh/id_ed25519_personal.pub
cat ~/.ssh/id_ed25519_work.pub
Enter fullscreen mode Exit fullscreen mode

Then go to each GitHub account β†’ Settings β†’ SSH and GPG Keys β†’ Add the corresponding key.

βœ… Now each GitHub account will recognize the right SSH identity.


πŸ§ͺ Step 5: Test SSH Profiles in VS Code Terminal

Personal:

ssh -T git@github-personal
Enter fullscreen mode Exit fullscreen mode

Work:

ssh -T git@github-work
Enter fullscreen mode Exit fullscreen mode

Expected output:

Hi your-username! You've successfully authenticated...
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ Step 6: Clone Repositories via SSH in VS Code

Inside VS Code:

Clone a personal repo:

git clone git@github-personal:your-username/personal-repo.git
Enter fullscreen mode Exit fullscreen mode

Clone a work repo:

git clone git@github-work:org-name/work-repo.git
Enter fullscreen mode Exit fullscreen mode

VS Code will respect the SSH config and use the correct keys β€” no more login prompts or permission errors.


πŸ” Step 7: Update Existing Git Remotes in VS Code

Already cloned with HTTPS? No worries!

Use this inside your project terminal:

git remote set-url origin git@github-work:org-name/work-repo.git
Enter fullscreen mode Exit fullscreen mode

Then you're fully synced and authenticated via SSH inside VS Code.


πŸ’‘ Bonus: Smooth Git Experience in VS Code

After this setup:

  • You can use the Source Control panel in VS Code without any SSH issues
  • You can commit, pull, and push with different GitHub accounts easily
  • Git logs, diffs, and branches all work without password prompts

🧠 Recap: SSH Profiles for GitHub in VS Code

Action Command
Create key ssh-keygen -f ~/.ssh/id_ed25519_name
Add to agent ssh-add ~/.ssh/id_ed25519_name
Configure profile ~/.ssh/config
Clone git clone git@github-profile:org/repo.git
Use in VS Code Automatically handled βœ…

🏁 Conclusion

By setting up SSH keys with profiles for personal and work accounts, and using them inside VS Code, you unlock a powerful and smooth Git workflow β€” no more access issues, no more login fatigue πŸ”₯


Got stuck? Want help with GitHub SSO or SSH key authorization for organizations?

Drop a comment below β€” happy to help you get fully connected!

Top comments (0)

πŸ‘‹ Kindness is contagious

If this post resonated with you, feel free to hit ❀️ or leave a quick comment to share your thoughts!

Okay