When we use Git management code, we often need to put it on different hosting sites, such as Github, OSC, etc., so different website accounts are different, we need to generate different keys, configure the corresponding different websites, next we write how to deal with it.

Ps: this is operating under centos7.2, but other operating systems are still applicable. For example, one is github and the other is osc.

1 Generating a Key

SSH is the path (the default path is used). Id_rsa_github is the name of the key file. Press Enter twice after naming the file, that is, the password is empty

ssh-keygen -T rsa -C "[email protected]" 
Copy the code

Generate the github keyGenerate the key for the OSC

SSH: id_rsa_github, id_rsa_github, id_rsa_osc, id_rsa_osc.

ls -a /root/.ssh 
Copy the code

2 Configure multiple accounts

Create a new file named config under the.ssh folder and edit the following

#github
       Host github.com    
       HostName github.com
       IdentityFile ~/.ssh/id_rsa_github
       User pinnuli

#osc
       Host gitee.com
       HostName gitee.com
       IdentityFile ~/.ssh/id_rsa_osc
       User pinnuli
Copy the code

(/images/git_multiaccount_config.png)

3 Place the public key on Github and OSC

4 Check whether the test is successful

ssh -T [email protected]

Copy the code

ssh -T [email protected]
Copy the code

Git multiple accounts have been configured, and more accounts are needed