Using Two GitHub Accounts on One Windows PC with SSH
Configured separate SSH keys and host aliases so one Windows PC can push to both personal and official GitHub repositories without replacing keys.
Purpose
Keep personal and official GitHub access separated on the same Windows machine by using different SSH keys and Git remote aliases.
Key points
- ›Each GitHub account should have its own SSH key
- ›The SSH config file maps friendly host aliases to different keys
- ›Git remotes use the SSH host alias, not plain github.com
- ›This avoids constantly removing or switching SSH keys between accounts
Notes
Note 1
Generate separate SSH keys
Create one key for the personal account and one key for the official account. Run these commands from PowerShell.
$ cd ~/.ssh$ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_personal$ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_official
Note 2
Add both public keys to GitHub
Copy each .pub file and add it to the correct GitHub account under Settings > SSH and GPG keys.
$ Get-Content ~/.ssh/id_ed25519_personal.pub$ Get-Content ~/.ssh/id_ed25519_official.pub
Note 3
Create or open the SSH config file
The SSH config file tells Windows which key to use for each GitHub account.
$ cd ~/.ssh$ New-Item -Name config -ItemType File$ code config
Note 4
Configure GitHub host aliases
Paste this into the config file. The Host values are custom aliases that Git will use later in the remote URL.
$ Host github.com-official$ HostName github.com$ User git$ IdentityFile ~/.ssh/id_ed25519_official$ IdentitiesOnly yes$$ Host github.com-personal$ HostName github.com$ User git$ IdentityFile ~/.ssh/id_ed25519_personal$ IdentitiesOnly yes
Note 5
Set the repository remote URL
Use the matching SSH alias in the Git remote URL. For a personal repository, use github.com-personal. For an official repository, use github.com-official.
$ git remote set-url origin git@github.com-personal:username/repository-name.git$ git remote -v
Note 6
Test the connection and push
Test SSH authentication first, then push normally.
$ ssh -T git@github.com-personal$ git push