Recently, I rebuilt the system and used win10. Before that, the development environment and configuration on the computer were cleared. Because of working reasons, I need to use Gitee (code cloud) and Github frequently. I used to configure one, but I don't know how to configure two at the same time, so I have this article.
Since Gitee and Github are configured at the same time, the following steps are naturally performed twice. Generally speaking, the account mailbox used on Gitee and Github should be different, so special attention should be paid to the configuration.
Create ssh key
# Enter the. ssh folder in the user directory, and the path will vary slightly depending on the operating system you use. # It doesn't matter if you don't have this folder. You can run the next command directly. cd ~/.ssh # Generate key and replace the email address with the email address you use for Gitee or Github ssh-keygen -t rsa -C "firstname.lastname@example.org"
Next you should see the following tips:
Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/your_user_name/.ssh/id_rsa): id_rsa_gitee
If this step returns by default, a file named id_rsa will be generated. You can input different names to facilitate the identification of the file. For example, the ssh key generated by Gitee can be set to id_rsa_gitee, and the ssh key set by Github can be set to id_rsa_github. I set it here to id_rsa_gitee.
Next you will see:
Enter passphrase (empty for no passphrase):
Enter directly and you will see:
Enter same passphrase again:
Just go back. Completed generation:
Your identification has been saved in id_rsa_gitee. Your public key has been saved in id_rsa_gitee.pub. The key fingerprint is: SHA256:F0K/ojCbFzgMPru11m4g/9uV03oHK+U0rKBLwOOye2c email@example.com The key's randomart image is: +---[RSA 2048]----+ | . | | . . | | . . o | | . + . . o | | o X . S o. | | .+.O o.o o* | | oo=o+. .+=.+ | | =++E. .oo+ . | | ++.*=o. .o . | +----[SHA256]-----+
Add public key to Gitee and Github
Find the. ssh folder in the user directory and view and copy the contents of the created id_rsa_gitee.pub or id_rsa_github.pub.
cd ~/.ssh # View the id_rsa_gitee.pub file content cat id_rsa_gitee.pub
It displays a bunch of things and duplicates them:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZbvgUEj3XAXH4HkW27ibdXgV6VHdrA9/WdSDHtiiC55mjPvxj3OtPxIbpeJmhWyHiJWR6 uUuK+gkb//O51uWCPhHqxKR7+45tZ9jHqXW+hEKPp+odQgc+3hiHAjTkn3JGeIJlQp2UdJCDHBrp+kcgVeg91+y7cU3ufaUQ/hpD rCgn6uvwjwJgnDhV9DYi+gFUFe7LUwa1o4nfwg43ycuOOuT7c6VO2dj/0pLRUVTPQYu/C3kaaPVedir7mKIu/dM6Ec44bhYTp1Dq qp8BO42Cfo+n+dempqYTe2wcPvuDjSj884IATc/KvBfc86Yd2Uj7NI7li90Y3i6adoxUIWQh firstname.lastname@example.org
Open the Gitee and Github websites to find the settings, then find SSH Keys, and add the duplicated public key.
Create a config file in the. ssh folder and add the following to distinguish the two ssh key s:
# gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_gitee # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_github
Test whether the connection is normal
On the command line, enter:
ssh -T email@example.com
If the following is returned, the Github connection is normal:
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.
Continue typing on the command line:
ssh -T firstname.lastname@example.org
If the following is returned, the Gitee connection is normal.
Welcome to Gitee.com, yourname!