git configure different mailbox different platforms ssh

Background: git of course you need to configure the company gitlab of ssh, also has its own github of ssh needs. Before then configure ssh way is not good enough.

Thinking: ssh generates different keys for different email accounts, and to configure the way the config file, files can be configured so git automatically using a corresponding secret key to complete verification according to different remote repository address.

Github to complete the configuration of ssh, ssh complete configuration gitlab again, and finally complete config file configuration.

Step: github Configuration

1, as a global select gitlab user's mailbox and email, as follows

                 git config --global user.name "你gitlab的用户名"

      git config --global user.email "你gitlab的邮箱"

2, generating SSH Key

 ssh-keygen -t rsa -C "你的gitlab账号对应的邮箱"

Been enter, if the key file already exists, you can overwrite

3, the default key file generated in /.ssh/ plate c, is id_rsa and id_rsa.pub, the open id_rsa.pub (preferably with notepad ++), the contents of which stick out into account in gitlab ssh configuration.

Click gitlab picture - "settings-" SSH Keys- "Key, after pasting, click Add key, as shown in

 

 Then try to clone gitlab the project to the local

 

github Configuration

1, and gitlab basically the same, only caveat is generated when the ssh key pair, not all the way to enter, need to rename it to a different file name, otherwise they will be covered; you can also specify the file name directly with the following command, such as

ssh-keygen -t rsa -C "你的gitlab账号对应的邮箱" -f ~/.ssh/id_rsa_github

2, the same secret key as the content of the suffix .pub paste into your account github ssh and generates the corresponding secret key.

3. At this point, if you try to clone your account remote repository project, you will find the connection fails. This is because the default git itself id_rsa secret key to ssh link.

4, adding the key to the SSH sgent, in order to allow SSH identify other private key.

ssh-add ~/.ssh/id_rsa_github,如果失败可以先执行以下命令
ssh-agent bash
 

Configuration config file

Into the .ssh directory, create a file without a suffix, edit the following into

Host github.com  
    HostName github.com  
    PreferredAuthentications publickey  
    IdentityFile ~/.ssh/id_rsa_github Host gitlab HostName 你的gitlab项目域名 PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa

Configuration configuration items is very important, it must be paired.

Then we need to be verified. Remember to turn on reconnection gitbash has ensured it takes effect.

Expansion: In dealing with this issue, to get new ideas from colleagues. That is related to the use of graphical administration tools sourcetree git to perform different configuration of ssh. Under tried quite convenient

Guess you like

Origin www.cnblogs.com/olio1993/p/12107232.html