GIT: How to manage multiple ssh keys on the local machine (Multiple Remote repository accounts), gitssh

Source: Internet
Author: User

GIT: How to manage multiple ssh keys on the local machine (Multiple Remote repository accounts), gitssh

Recently, I have been studying git. I recommend a git tutorial that I think is very good. After learning, I have changed from a new git beginner to a git entry. I still need to continue working hard.

Instructor Liao's git learning tutorial (other basic git knowledge points will not be introduced in this blog. Let's take a look at the tutorial and study it. The instructor's explanation is very good and easy to understand ):

Http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000.

Here is a problem encountered by myself, through reading the information, most of the content reposted URL: https://segmentfault.com/a/1190000005607713, thank you very much this great god, also share to other friends who love git. We may need to use git with different github accounts on a computer. In this case, we need to solve the problem of how to manage multiple ssh keys on the local machine (scenario: for example, if you have an account for the remote repository of the github website and an account for the remote repository of the company, to facilitate the pull and push of different repository codes, you need to configure multiple ssh keys ).

 

Generate new ssh key

If an ssh key already exists on our computer, we need to generate the second id_rsa you want to use on our computer. Run the following command:Ssh-keygen-t rsa-C "Your github account".

The red part will prompt you where to store the newly generated id_rsa, which is stored under the user name of drive C by default. in the ssh folder (that is, the directory where your first github user ssh key is stored), we need to enter the path/c/Users/DodoMonster /. ssh (note that this path is the directory for storing the ssh key in the user directory on your system disk. Please use the corresponding directory on your computer ), finally, I renamed the ssh key with "id_rsa_gman" to prevent the existing ssh key from being duplicated by default.

After entering the path, you will be prompted to enter the verification password you entered when submitting the project. If you do not enter the password, it means you do not need the password. This is to prevent others from pushing anything on your project at will, so you 'd better enter your password. Press enter, and then enter again to confirm the press enter (either way press enter, there is no password ).

 

Add new ssh key

By default, SSH only reads id_rsa. To enable SSH to identify the new private key, you need to add it to the SSH agent.
Run the following command:ssh-add ~/.ssh/id_rsa_gman

If the error message "cocould not open a connection to your authentication agent. Unable to connect to the ssh agent" is returned, runssh-agent bashRun the commandSsh-add command

 

Configure the config file

Check whether the config file exists in the. ssh file.

If the config file already exists, edit the config file with the following command:vim config# This is a linux Command. after entering the vim interface, pressA or I or A or IEnter the editing mode. After editing, Press esc to enter:wqSave the file and exit

If the config file does not exist, create a config file. Run the following command:touch configAnd then edit the config file.

Configure the config file:

# Default github user (DodoMonster@email.com)-This is actually a comment Host github # Set the Default commonly used github Host to github.com better HostName github.com PreferredAuthentications publickey IdentityFile ~ /. Ssh/id_rsa_me

The Host name can be easily remembered, but the HostName must be github.com.

#*************************************** *********
# Second user (monster@qq.com) Host monster HostName github.com PreferredAuthentications publickey IdentityFile ~ /. Ssh/id_rsaPs: HostName is a domain name
Test whether the configuration is successful

Run the following command:

   ssh -T git@github.com   ssh -T git@github        

The welcome message is successfully configured.

Note: After the configuration is complete, make some changes to the address of the remote database when the Host is not the github repository of github.com. For example, add orderTicket, a repository under the monster account., You need to use the following command to add:

git remote add test git@github:monster/orderTicket.git

Instead of the original git@github.com: monster/orderTicket. git (so that each connection uses id_rsa to connect to the server ).

The configuration is now complete!

 

In addition, note: github according to the configuration file user. email to obtain github account display author information, so for multi-account users must remember to change user. email to the corresponding email (monster@mail.com ).

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.