Gitee and Github simultaneously configure ssh key

Posted by Bubbagump on Wed, 01 Apr 2020 07:38:47 +0200

1, Create ssh key of gitee and github

cd ~/.ssh
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"

Replace the correct mailbox, press enter

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/FlyingHorse/.ssh/id_rsa): id_rsa.gitee

Enter id_rsa.gitee when creating the ssh key of gitee and id_rsa.github when creating the ssh key of GitHub

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:lmjU8A4k+r6liYJmENBPM/7Frx3XDg98VeWvIQ9dLyw xxxxx@xxxxx.com
The key's randomart image is:
+---[RSA 2048]----+
| .  . o         o|
|. ..+o +       ..|
|. .+ oo.o       +|
|.  .o. +o.   o .+|
| .  ..o.S. .E.=.o|
|.  . ...  o ==o+ |
|o   . .  o o *o  |
|oo . =  . .   o  |
|o.. +            |
+----[SHA256]-----+

Press enter all the way, and the output is as shown in the figure

2, Copy public key to gitee or github

$ cat id_rsa.gitee.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZbvgUEj3XAXH4HkW27ibdXgV6VHdrA9/WdSDHtiiC55mjPvxj3OtPxIbpeJmhWyHiJWR6
uUuK+gkb//O51uWCPhHqxKR7+45tZ9jHqXW+hEKPp+odQgc+3hiHAjTkn3JGeIJlQp2UdJCDHBrp+kcgVeg91+y7cU3ufaUQ/hpD
rCgn6uvwjwJgnDhV9DYi+gFUFe7LUwa1o4nfwg43ycuOOuT7c6VO2dj/0pLRUVTPQYu/C3kaaPVedir7mKIu/dM6Ec44bhYTp1Dq
qp8BO42Cfo+n+dempqYTe2wcPvuDjSj884IATc/KvBfc86Yd2Uj7NI7li90Y3i6adoxUIWQh xxxxx@xxxxx.com

View the public key, enter id_rsa.gitee.pub for gitee, and enter id_rsa.github.pub for GitHub

Copy the second line to the end to the ssh of gitee or github to save

3, Create configuration to resolve ssh conflict

Create the 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

4, Test connection

input

$ ssh -T git@gitee.com

If you return to the figure below, the connection of gitee is normal

Welcome to Gitee.com, yourname!

Input

$ ssh -T git@github.com

If you return to the figure below, the connection of github is normal

Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.

Topics: ssh github git shell