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
π For work GitHub:
ssh-keygen -t ed25519 -C "yourwork@email.com" -f ~/.ssh/id_ed25519_work
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)"
Add both keys:
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
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
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
π 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
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
Work:
ssh -T git@github-work
Expected output:
Hi your-username! You've successfully authenticated...
π¦ 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
Clone a work repo:
git clone git@github-work:org-name/work-repo.git
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
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)