Configure different public keys for github and gitee

When there are multiple git accounts, one gitee is used for company projects and one gitee is used for own development activities. How to configure public keys for two different websites?

The following instructions are executed under the git bash command box

Solution:
1. First open the git terminal, use the cd ~/.sshcommand to enter the .ssh directory, and generate the public key of gitee.

If the .ssh folder does not exist, use the mkdir ~/.sshcommand to automatically create it

$ ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitee_id_rsa
Then press Enter three times (Enter command)
2. Generate the public key of github and press
$ ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github_id_rsa
Enter three times

The above two mailboxes can be different, but in order to facilitate memory, it is recommended to set the same

Generate the following files (the config file is added for later steps):
file
3. Add public keys for gitee and github
Use cat gitee_id_rsa.pubcommands to get the public key of gitee,
cat github_id_rsa.pubget the github public key, and copy and paste it to the SSH public key location.
Insert picture description here
Insert picture description here

4. Create a new config file in the .ssh file directory
$ vi config

After using the above command, copy the following content to the command window, press Esc (used to exit the editing state) , and then press **Z (capital letter)** twice, at this time, it can automatically save and exit the window.

Add the following content (where Host and HostName fill in the domain name of the git server, and IdentityFile specifies the path of the private key):

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

5. Test
Enter in the command window to
ssh -T [email protected]
ssh -T [email protected]
Insert picture description here
get the information as shown in the figure, indicating that the public key is set successfully!
Reference link

Guess you like

Origin blog.csdn.net/weixin_44333597/article/details/109060885