Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Created March 8, 2015 13:09
Show Gist options
  • Select an option

  • Save githubutilities/0e5df6493b7d528f1e75 to your computer and use it in GitHub Desktop.

Select an option

Save githubutilities/0e5df6493b7d528f1e75 to your computer and use it in GitHub Desktop.
Multiple SSH Keys for Multiple Github Accounts

Multiple SSH Keys for Multiple Github Accounts

Generate another ssh key

# generate ssh key and save to `id_rsa_another`
$ ssh-keygen -t rsa -C "[email protected]"

# save your key
$ ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_rsa_another

# delete all your cached keys
$ ssh-add -D
# list all your saved keys
$ ssh-add -l

add the public key id_rsa_another.pub to github through github setting

edit your ssh config file under ~/.ssh/config

#origin account
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa

#new account
Host github.com-newusername
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_another

Modify git config

$ git config user.name "username"
$ git config user.email "[email protected]" 

Change your git remote

e.g. you have to change [email protected]:githubutilities/homebrew-cask.git to [email protected]:newusername/homebrew-cask.git for this to works

your can run git remote -v to get the push url.

Now you can commit your changes

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment