gitee和github同时配置ssh key
由于国内的 GitHub 访问比较不稳定有时候会选择 Gitee 作为 GitHub 的备用方案。再有,国内有些开源项目只有在 Gitee 发布。所以做个备用方案是很有必要的。一下是整个配置
创建Gitee和Github的ssh key
cd ~/.ssh
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
替换正确的邮箱,按 enter
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/FlyingHorse/.ssh/id_rsa): id_rsa.gitee
创建 Gitee 的 ssh key 时输入 id_rsa.gitee,创建 github 的 ssh key 时输入 id_rsa.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]-----+
一路按 enter,直到输出如上所示
把 public key 复制到 gitee 或 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
查看公钥,Gitee 输入 id_rsa.gitee.pub,Github 输入 id_rsa.github.pub
将第二行到结尾的内容复制到 Gitee或 Github 的 ssh 中保存
创建配置文件解决 ssh 冲突
在 .ssh 文件夹中创建 config 文件,添加以下内容以区分两个 ssh key
# 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
测试连接
输入
ssh -T git@gitee.com
若返回如下结果,则Gitee则连接正常
Welcome to Gitee.com, yourname!
输入
ssh -T git@github.com
若返回如结果,则 github 则连接正常
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!