Multiple SSH Keys settings for different github account

Check existing keys

$ ssh-add -l

Create different public key

create different ssh key according the article Mac Set-Up Git

cd ~/.ssh
ssh-keygen -t rsa -C "" -f "github_bustroker"
ssh-keygen -t rsa -C "" -f "github_bkr"

The -C option is a comment to help identify the key. The -f option specifies the file name for the key pair.

for example, 2 keys created at:


then, add these two keys as following

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

you can delete all cached keys before

$ ssh-add -D

finally, you can check your saved keys

$ ssh-add -l

Modify the ssh config

$ cd ~/.ssh/
$ touch config
$ nano config

Then added

#bustroker account
    User git
    IdentityFile ~/.ssh/id_rsa_bustroker

#bkr account
    User git
    IdentityFile ~/.ssh/id_rsa_bkr

The Host is an alias for the connection info. It can be use in git@[alias]:[user_name]/[repo_name].git


ssh -T git@[alias]

Clone or add origin to your repo

Use alias in repos urls as: git@[alias]:[user_name]/[repo_name].git

To clone the repos

git clone[repo_name]
git clone[repo_name]

Or to add remote. If copying the command from github, make sure to replace with the right alias, e.g.

git remote add origin[repo_name]