Git multiple sets of public, private key configuration and use

Source: Internet
Author: User
Tags ssh
git multiple sets of public, private key configuration and use

The configuration of multiple sets of public private keys and the use of business usage scenarios to check if there is already a corresponding SSH key to generate a new SSH key and add to Ssh-agent to add the generated SSH key connection to the corresponding account to test the non-GitHub project How to configure the FAQ

Business Usage Scenarios

In the actual development of the individual, we often encounter a scenario where a person has both a GitHub account (personal) and a company's Git account (the company's private repository), or a person who has multiple github accounts at the same time, in which case, to use Git in a simple and easy way, So it is inevitable to configure multiple sets of public and private keys (SSH key), even so, there are several git accounts, then inevitably need to how many sets of public and private keys. In the case of a single account, we are using the Id_rsa (private key) and id_rsa.pub (public key), obviously the default can only support one, then if there are multiple accounts, then what to do. Please read the detailed articleStepsCheck to see if the appropriate SSH key has been generated SSH key and added to Ssh-agent to add the generated SSH key connection test FAQ in the corresponding accountcheck if the appropriate SSH key already existsOpen Terminal input Ls-al ~/.ssh
Take My personal example:

As you can see, there are 3 sets of SSH keys (one set of mosaics) in the interface, a set of default, a set of GitHub's, and a mosaic-hit set. Of course, this is my installation after, if you have not installed before, in theory is a set of none, no, nothing to do with, we build on our own to check out the SSH key is there already exist, if you do not see the public key pair listed, or do not want to use the previous public key pair, You can choose the following steps to generate a new public key pairgenerate a new SSH key and add it to ssh-agentOpen terminal using SSH key generation command: Ssh-keygen-t rsa-b 4096-c "your_email@example.com"
Note:The following mailbox corresponds to the corresponding account of the mailbox, if it is GitHub account, and registered account mailbox for xxxx@qq.com, then the command behavior: ssh-keygen-t rsa-b 4096-c "xxxx@qq.com
Next you will be prompted to save the name of the SSH key and the path. The default path is (/USERS/YOU/.SSH/ID_RSA) (you are the user's personal directory). This step is important, if you use the default, and the next account is also using the default path and file name, then the previous SSH key will be generated by the SSH key rewrite, resulting in the previous account is not available. So the right thing to do is to give it a name and roar with the name of the app, because it's easier to distinguish. Here is my personal match:/users/hongqiangren./.ssh/github_rsa

Next, you will be prompted to set the SSH security password. This step can use the default (that is, do not set the password), directly press ENTER. For more details on SSH key password settings, you can access: "Working with SSH key passphrases"

After SSH key is generated, the next step is to add a proxy for SSH key, which will allow the request to automatically correspond to the corresponding account. Many articles on the Web write to the need to configure the config file, by my pro-test, in fact, is not required, in the generation of SSH key, by adding a proxy for the generated SSH key, to add the proxy command for SSH key: Ssh-add ~/.ssh/xxx_rsa,xxx_ RSA is the private key name of the SSH key you generated. The following figure takes my own example (this machine is OS X system)
add the generated SSH key to the corresponding Git account in the appropriate account, here on GitHub for example, click on the user image after login, select: Setting. Login to GitHub:
Locate ssh and GPG keys, click and add SSH key


Get the generated public key, open the terminal, using the command line: Cat ~/.ssh/xxxx.pub, here's my personal public key, for example:
Copy the content and paste it into the key above. Then click Save
Connection Test

Next we test whether the configuration is successful, open the terminal, enter: Ssh-t git@github.com

If the above information is displayed, then congratulations, the public key has been successfully configured. :-) How to configure a non-GitHub project.

For non-GitHub type of public and private key configuration, in fact, is very similar, because of the secrecy involved, I am not convenient to talk about the company's git public key configuration paste out (in fact, the same as the above). Believe that smart small partners can configure their own company's SSH key FAQ based on the above information

Reason, the reason for writing this article, is because before encountering this pit, in the Internet to find articles, found a variety of copied to copy, and did not actually solve the problem. Since I see no article that makes me feel good, and can actually solve the problem, it happens that I just solved the related problem, it is better to write an article. Hope to help some small partners!

Paste the configuration process may encounter problems and workarounds link

Troubleshooting with SSH
Error:permission to User/repo denied
Error:key already on use
Error:agent ad Mitted failure to sign

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.