一电脑多git的ssh key配置

风吹草动 2020-06-25

原本就用一个github,但毕竟国外的,网速有点。。。疼,所以又准备用上以前的gitee,为了统一管理好ssh 的key,如下:

首先生成针对不同代码平台生成两个不同的秘钥对,注意邮箱要用你在平台上对应的邮箱

码云和github的秘钥生成过程
右键git bash here 后执行如下命令:
MINGW64 ~/Desktop
$ ssh-keygen -t rsa -C"我的邮箱" -f ~/.ssh/gitee_id_rsa
Generating public/private rsa key pair.
/c/Users/myHostAccout/.ssh/gitee_id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:------------------------------------------------------我的邮箱1
Your identification has been saved in /c/Users/myHostAccout/.ssh/gitee_id_rsa.
Your public key has been saved in /c/Users/myHostAccout/.ssh/gitee_id_rsa.pub.
The key fingerprint is:
SHA256:STlBJWWFEjll7*************dBs5Z73xM00 我的邮箱
The key‘s randomart image is:
+---[RSA 2048]----+
| .OX*ooo.o+|
| oxxxxE|
| .*+o.=+.=B|
| .o+.*...=o|
| S.. . o.o|
| ..|
| .|
| |
| |
+----[SHA256]-----+

MINGW64 ~/Desktop
$ ssh-keygen -t rsa -C "我的邮箱" -f ~/.ssh/github_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:------------------------------------------------------我的邮箱2
Your identification has been saved in /c/Users/myHostAccout/.ssh/github_id_rsa.
Your public key has been saved in /c/Users/myHostAccout/.ssh/github_id_rsa.pub.
The key fingerprint is:
SHA256:ouObNqYUAj9**********R6qwSJwjf0ZcaDDDZDhQ 我的邮箱
The key‘s randomart image is:
+---[RSA 2048]----+
| .E=... |
| o.oo = |
|. o. |
|xxxxxxxxxx        |
|oo+.o.*+S |
|..++o=.. |
| .+o o |
| ...++ |
| .==o |
+----[SHA256]-----+

然后在生成秘钥的 .ssh目录下创建config文件:

需要注意的是IdentityFile配置的是私钥文件

#github
Host github.com
HostName github.com
IdentityFile C:\Users\xxxx\.ssh\github_id_rsa
PreferredAuthentications publickey
User 我的邮箱(名字任意)

#osc
Host gitee.com
HostName gitee.com
IdentityFile C:\Users\xxxx\.ssh\gitee_id_rsa
PreferredAuthentications publickey
User 我的邮箱(也可是其他的)

把各自公钥加入各自平台的公钥库中,

连接一下试试,ok

一电脑多git的ssh key配置

相关推荐