SSH Keys

Problem

How to create multiple github accounts and git push or pull automatically?

Solution

generate different ssh key

ssh-keygen -t rsa -C "Hadley_hzy@hotmail.com"
ssh-keygen -t rsa -C "Hou.z@husky.neu.edu"

for example, 2 keys created:

~/.ssh/id_rsa_hadleyhzy
~/.ssh/id_rsa_hadleyhzy34

Adding a new SSH key to your Github account

check this link

Edit ssh config file ~/.ssh/config

Host github.com-Hadleyhzy
        HostName github.com
        User hadleyhzy
        IdentityFile ~/.ssh/id_rsa_hadleyhzy

Host github.com-Hadleyhzy34
        HostName github.com
        User hadleyhzy34
        IdentityFile ~/.ssh/id_rsa_hadleyhzy34

Add ssh private keys to your agent

ssh-add ~/.ssh/id_rsa_hadleyhzy
ssh-add ~/.ssh/id_rsa_hadleyhzy34

check your saved keys:

ssh-add -l

Test your connection

ssh -T git@github.com-Hadleyhzy
ssh -T git@github.com-Hadleyhzy34

git clone your repositories

git clone [password-protected SSH key]

change git@github.com to git@[Host], [HOST] is defined in your ~/ssh/config file.

set up user name and email

git config user.name [user.name]
git config user.email [user.email]
PREVIOUSDecision Tree
NEXTProbablity Theory in Summary