Creating Multiple SSH Key Settings For Github Accounts

Posted on Wed 29 March 2017 in git

Create a new ssh key for the second account

$ ssh-keygen -t rsa -b 4096 -f "$HOME/.ssh/masecondgit_rsa

Create an ssh config

Create a file at ~/.ssh/config

# create the first host to use your original key as default
Host github.com
    IdentityFile ~/.ssh/id_rsa
    HostName github.com
    User mikeabrahamsen

# create a second host to use with the second github account
Host github.com-secondgit
    HostName github.com
    User mikeabrahamsen
    IdentityFile ~/.ssh/masecondgit_rsa

Now to use the second account with the ssh key use the following when you clone:

# notice the '-secondgit' before the ':'
git clone [email protected]:mikeabrahamsen/dotfiles.git

If you want to add this to an already created repo

git remote add origin [email protected]:mikeabrahamsen/dotfiles.git