How to setup multiple ssh keys for your githubOct 22, 2016
The problem we faced usually when you deal with version control, is that, you probably have multiple github accounts and want to maintain various repositories accordingly. Say you have two github accounts: git_A and git_B, and you create repositories repo_a and repo_b under these two accounts.
Github usually will suggests you to generate your public key and associate them with your account. If you’re not familiar with ssh-keygen for github, please refer to this post.
Now you need to generate two different public keys for git_A and git_B. This is what you expect when follow the ssh-keygen:
This is where you name your public key, e.g., id_rsa_git_A.pub. Soon you will have two public keys in /Users/YOURNAME/.ssh/
Now let’s associate with your git accounts. Open your ssh config with any editor you like:
And add two sections accordingly in the config file:
The name after Host can be any thing you like to identify your git account, obviously they are associated with different private keys here. Now you can test it with ssh, e.g.:
They should be automatically using corresponding public key now, and you will get successful message response.
To init and config a repository locally, you probably will do: