Skip to content

Instantly share code, notes, and snippets.

@lokesh-webonise
Created June 27, 2013 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokesh-webonise/5875984 to your computer and use it in GitHub Desktop.
Save lokesh-webonise/5875984 to your computer and use it in GitHub Desktop.
github authentication with multiple keys
Multiple github account SSH key switch
github using SSH connection with the client. If it is a single-user (first), generate a key pair, the public key saved to github, each time you connect the SSH client sends local private key (default ~ / .ssh / id_rsa) to the service-side validation. Single-user case, the connection saved on the server's private key and send the public key is naturally paired. But if it is a multi-user (first, second), we are connected to the second account when, second save their own public key, but still send the default SSH client private key, the private key that is first, then the verification will naturally be through. However, to achieve multiple accounts under the SSH key to switch on the client to do some configuration can be.
First, cd to ~ /. Ssh using ssh-keygen-t-rsa-C 'second@mail.com' to generate new SSH key: id_rsa_second, after generating a new SSH public key will be added to github.
ssh-keygen-t-rsa-C 'second@mail.com'
Default SSH only reads id_rsa, so in order to allow identification of new SSH private key, you need to add it to the SSH agent
ssh-add ~ / .ssh / id_rsa_second
If the command error: Could not open a connection to your authentication agent. Unable to connect to ssh agent, ssh-agent bash executable command before running ssh-add command.
After completing the above steps in ~ /. Ssh directory creation config file that corresponds to the private key is used to configure the server. Reads as follows:
# Default github user (first@mail.com)
Host github.com
HostName github.com
User git
IdentityFile C :/ Users / username / .ssh / id_rsa
# Second user (second@mail.com)
Host github-second
HostName github.com
User git
IdentityFile C :/ Users / username / .ssh / id_rsa_second
Once configured, the connection non-default account github warehouse, the address of the remote database to correspond to do some changes, such as adding second account is now a warehouse under test, you will need to add this:
git remote add test git @ github-second: second / test.git # not original git@github.com: second / test.git
So each connection will use id_rsa_second connection with the server. At this point, you're done!
Note: Depending on the configuration file user.email github to get github account display author information, so for multi-account users must remember to user.email converted into the corresponding email (second@mail.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment