Windows post for git installation and SSH Key Management

Source: Internet
Author: User

First, installation environment

1. Native system: Windows ten Pro (64-bit)
2. Git version: Git-2.11.0-64-bit.exe (64-bit)

Second, git installation

Go to the official website after downloading the next step to complete the installation, such as:


See if the configuration is in the system environment variable after installation


Then right-click on the desktop, choose Git bash here, and enter the following code:

git --version #验证git是否安装成功,输出版本号就代表安装成功

Such as:


The installation is complete with the configuration of the global user name and mailbox, enter the following command:

git config --global user.name "自定义用户名"git config --global user.email "邮箱"

Use the following command to cancel the global setting:

git config --global --unset user.namegit config --global --unset user.email

Third, Git generates a single SSH key and manages multiple SSH keys generated

1. Generate a single SSH Key, enter the command "command description" below

ssh-keygen -t rsa -C "[email protected].com"

A single SSH key can be generated consecutively, without entering the key file name and password


The build will generate two files under "C:\Users\ username. SSH",


2. Manage multiple SSH keys generated by git
Problem description
When you have more than one Git account, such as a GitHub, for some of your own development activities, a gitlab, typically a git inside the company. If your mailbox is different, it will involve a problem, and the first key will be overwritten when you generate the second Git key, leading to the inevitable use of one.

Workaround
We can create a new config file in the "~/.SSH" directory to configure, you can solve the problem

Specific steps

    • Generate the first SSH key (I'm using GitHub's mailbox here)
ssh-keygen -t rsa -C "[email protected]"

Go to "C:\Users\ username. SSH", right-click-Choose Git bash here, this step is important, otherwise enter the key name below, the key will be generated in the current open git bash under the path, such as my desktop open git bash, will be generated on the desktop, of course, you can also complete the path before entering the name. Such as:


Here I do not "enter" but to the generated key named "Id_rsa_github", the following two consecutive returns, no password to set the key (see personal needs)

    • Generate another SSH key (the company email I used here)
ssh-keygen -t rsa -C "[email protected]"

The resulting file looks like the following:


    • Execute ssh-agent command

Ssh-agent is a key manager, after running ssh-agent, use Ssh-add to the private key to ssh-agent custody, other programs require authentication when the authentication request can be submitted to Ssh-agent to complete the certification process


    • Add private key
ssh-add ~/.ssh/id_rsa_githubssh-add ~/.ssh/id_rsa_gitlab

When you execute the Add private key command above, the following error occurs:


Here's how to fix it:
1. Enter the following command to view the ssh-agent thread that is turned on


ps aux | grep ssh

Execute the following command to kill the thread:

kill -9 线程号

Enter the. SSH directory under the user's list, open git bash and execute the following command

exec ssh-agent basheval ssh-agent -sssh-add ./id_rsa_github

The second private key is added to the "Ssh-add./id_rsa_gitlab" Execution


    • Create and modify config file

1. Create the config file and create the file in the ". SSH" Directory
① Create a new txt text under Windows, and then change the name to config (including the. txt suffix)
② under Git bash, directly touch config to create a config file

2, edit the config file, modify the following content:

# gitlabHost gitool.glanway.comHostName gitool.glanway.comPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa_gitlabUser yangjie# githubHost github.comHostName github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa_githubUser yangjie

Configuration file Description:
Each account is configured with a single host, each host to take an alias, each host configuration HostName and identityfile two properties can be
The name of the Host can be the name you like, but this will affect git-related commands
For example:
Host Mygithub This definition, the command is as follows, [email protected] immediately after the name changed to Mygithub
git clone [email protected]Mygithub:P opfisher/androidrotateanim.git
The equivalent of your configured HostName real domain name, mapped to the configuration name behind Host

HostName                      #这个是真实的域名地址IdentityFile                  #这里是id_rsa的地址PreferredAuthentications      #配置登录时用什么权限认证--可设置publickey,password publickey,keyboard-interactive等User                          #配置使用用户名

"Note" Do not add comments such as the following in the configuration file

HostName git.glanway.com //这里填你们公司的git网址即可

This comment will cause an error when reading the configuration file and is not recognized

3. Add the public key to GitHub and Gitlab
4. Testing
See the following output indicates a successful configuration

ssh -T [email protected]          #测试githubssh -T [email protected]   #测试gitlab

Reprinted from:
The coding of the finger
Links: http://www.jianshu.com/p/a3b4f61d4747
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Windows post for git installation and SSH Key Management

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.