Skip to content

Instantly share code, notes, and snippets.

@cemckinley
Last active December 20, 2015 10:49
Show Gist options
  • Save cemckinley/6118445 to your computer and use it in GitHub Desktop.
Save cemckinley/6118445 to your computer and use it in GitHub Desktop.
Use two or more usernames/SSH keys for remote git repos

##Using Multiple SSH Keys With Git

Unless specified, Github and other remote repositories will use the default SSH keys, usually at /Users/<you>/.ssh/id_rsa. The SSH key is associated with the email you entered when you created it, so in order to use a different email/username/ssh key combo for another remote repository, you'll have to do the following:

  1. Create a new SSH key following the same directions here: https://help.github.com/articles/generating-ssh-keys, but when prompted to enter the file name, name it something like /Users/<you>/.ssh/id_rsa_somethingelse instead.
  2. Look for a file in ~/.ssh/ called 'config'. If it doesn't exist, create one. (No extension).
  3. Add this to the file and save it:
Host <someremotedomain>
    User git  
    Hostname <someremotedomain>  
    IdentityFile ~/.ssh/id_rsa_somethingelse
  1. Register your new SSH key by opening terminal and typing: ssh-add ~/.ssh/id_rsa_somethingelse
  2. Add (or delete then re-add) a remote url for the repository: git remote add <some alias> <remote ssh url with someremotedomain in it>

Any time you add a remote url to a local project with <someremotedomain> in the remote url, the ssh key used will be the key specified in the ssh config file for that Host.

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