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 "bustroker@email.com" -f "github_bustroker"
ssh-keygen -t rsa -C "bkr@email.com" -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:
~/.ssh/github-bustroker
~/.ssh/github-bkr
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
Host github.com-bustroker
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_bustroker
#bkr account
Host github.com-bkr
HostName github.com
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
Test
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 git@github.com-bustroker:bustroker/[repo_name]
git clone git@github.com-bkf:bkr/[repo_name]
Or to add remote.
If copying the command from github, make sure to replace @github.com
with the right alias, e.g. @github.com-bkr
git remote add origin git@github.com-bustroker:bustroker/[repo_name]