Managing Multiple SSH Keys for Different GitHub Accounts

Goal

Use different SSH keys for multiple GitHub accounts on the same machine.

Generate SSH Key Pairs

cd ~/.ssh
ssh-keygen -t rsa -C "bustroker@email.com" -f "github_bustroker"
ssh-keygen -t rsa -C "bkr@email.com" -f "github_bkr"

This creates:

~/.ssh/github_bustroker
~/.ssh/github_bustroker.pub
~/.ssh/github_bkr
~/.ssh/github_bkr.pub

Configure SSH

cd ~/.ssh/
touch config
nano config

Add host aliases for each account:

##bustroker account
Host github.com-bustroker
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_bustroker

##bkr account
Host github.com-bkr
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_bkr

Test the connection:

ssh -T git@github.com-bustroker
ssh -T git@github.com-bkr

Add Public Keys to GitHub

Copy each public key to its corresponding GitHub account under Settings → SSH and GPG keys:

Use the Correct Alias When Cloning

Replace github.com with your host alias:

git clone git@github.com-bustroker:bustroker/[repo_name]
git clone git@github.com-bkr:bkr/[repo_name]

Or when adding a remote:

git remote add origin git@github.com-bustroker:bustroker/[repo_name]

Optional: Add Keys to SSH Agent

On Windows

Enable and start the OpenSSH Authentication Agent service:

Start-Service ssh-agent

Add Keys

ssh-add ~/.ssh/github_bustroker
ssh-add ~/.ssh/github_bkr

List loaded keys:

ssh-add -l

Clear all keys if needed:

ssh-add -D