About git ssh-key: solves the problem of multiple local ssh-keys, gitssh-key

Source: Internet
Author: User

About git ssh-key: solves the problem of multiple local ssh-keys, gitssh-key
When setting github, the official instructions require that the current id_rsa be backed up and a new private key be generated for github login. If this is done, the new private key cannot continue to log on to the previous machine. This method is a bit violent...
Fortunately, ssh allows us to log on to different domains using different private keys.


When adding a private key, you can specify different file names to generate different private key files.

ssh-keygen -t rsa -f ~/.ssh/id_rsa.work -C "Key for Work"ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "Key for GitHub"

Add ssh configuration files and modify permissions

touch ~/.ssh/configchmod 600 ~/.ssh/config

Modify the content of the config file

Host *.workdomain.com    IdentityFile ~/.ssh/id_rsa.work    User lee Host github.com    IdentityFile ~/.ssh/id_rsa.github    User git
In this way, ssh will read the corresponding private key file based on different domains.
ssh -T git@github.com



How to create an ssh-key

The ssh method is required for downloading code using repo git. Currently, the password method is not supported for downloading code, and only the ssh-key method is supported, users who need to download the code should generate an ssh-key locally according to the following method, and then send the corresponding certificate file to the moderator or administrator. After obtaining the permission to download the code, they can download it directly; set the access permission. The new git library adopts the certificate authentication method. Please run the following command on your local machine: # ssh-keygen will enter the information in ~ /. Generate the id_rsa.pub file and id_rsa file under the ssh directory. Please send the id_rsa.pub file to me (moderator ). Then, use the id_rsa certificate when using ssh. The generated ssh certificate is automatically provided when linux and MacOS log on via ssh. On windows, you can use xshell or putty to create a certificate. Currently, no password is provided for logon.

What are ssh and git in the end? The plain image must be explained in a simple way and you will understand it. Do not use too many technical terms,

SSH is a security authentication protocol, and Git is a version management tool.

For SSH, if you think the term "Security Authentication Protocol" is too troublesome, you should treat it as a "connection code. I don't know if you want to watch the spy films. If there is no wireless communication device in the Underground Works of the films, you need to connect two people. For the sake of security, underground workers are all single-line contacts, and only their immediate superiors know their real identities, so the two people in the connection have never met each other and do not know each other. In this way, there is a question: how can the contact ensure that the other party is not impersonating? Connector signals play a crucial role in this process. A: What do you want? B: casual. A: It is not sold here! B: Let's get a dish of peanuts. The above is a typical joint scenario. What B said is an important credential. With this sentence, Jia can confirm that he is not impersonating. If B directly says that he has a dish of peanuts or ordered other dishes, then he is not a common citizen, but an enemy. The ssh protocol is similar to the connector password. Before party a formally communicates with Party B, Party A requires Party B to present the pre-confirmed credential (the connector password is used, while ssh is a long string of English characters ), then compare it with your own. If it is the same, you can begin to exchange information. If it is different, it will be terminated immediately. Of course, security is the most important feature of the ssh protocol. He also has some other features, such as compression and transmission, which can be found in the encyclopedia.

Git is mainly used to manage large-scale software development projects. To make it easier to understand, I will give an example by writing a Word document. Assume that you are writing a hundred-page Word document. I think it is almost the same, and the content and format have reached the perfect realm. But the next day I woke up and suddenly got a new idea while I was still in bed, but I was not sure whether I could make the Word document more perfect, I am afraid that the changes cannot be restored to the present state. Without any tool assistance, you may create a new directory, name it "backup", and copy the current Word document to the backup directory, append the current time after the file name, indicating that this is the backup of the day. After you finish the work, you can safely modify the changes, but the modified results are not satisfactory. Therefore, you decided to discard the changes and replace the modified documents with the documents in the backup directory, in this way, the original image is restored. In the process of completing the entire word, maybe such a scenario will be repeated several or even dozens of times, will it feel a little annoying? If you have git, you don't have to worry about it. You do not need to create a backup directory or copy files again and again. Every time you make changes, she will take the initiative to help you back up the current document like a caring Secretary MM (of course, she did not create a backup directory, and she had her own tricks ), you don't feel the existence of such a process. You can make any changes at any time with no need to consider whether the changes can be restored to the previous state in case of modification failure, because git can help you quickly and accurately restore the changes to the previous State at any time, in this process, you only need to enter a few English words to execute the command. Of course, Git is far more than that. This is just a typical application scenario of Git, and it is just a bit of her skills. If you are interested, you can learn about version management or configuration management.

I can only talk about this level with limited capabilities. I don't know if you can understand it.

Related Article

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.