在 Github 和 Gitee 配置多个 SSH Key
在 Github 和 Gitee 生成、添加、部署不同的 SSH Key
环境
git version 2.35.1.windows.2
生成 SSH Key
在bash
中分别执行生成 ssh key 的指令,
1 | ssh-keygen -t ed25519 -f ~/.ssh/github_id_ed25519 -C "Github-220210" |
-t
指定密钥的类型,这里选择 github 和 gitee 文档中都使用的ed25519
-f
指定密钥生成的目录和文件名,Windows 平台 ssh 的默认目录为用户文件夹/.ssh/
, 文件名可以按需修改。
-C "comment"
中的comment
很多网站和文档都写自己的邮箱,事实上可以随意修改,只是作为一个标识。
配置 SSH Config
在 ssh 目录~/.ssh/
中新建一个config
文件,添加内容:
1 | # github |
Host
, Hostname
填写 Git 服务器域名
IdentityFile
填写 SSH Key 私钥文件的位置
配置 SSH Key 公钥
在
~/.ssh/
目录中找到对应的*.pub
文件,复制其中的内容在 Github, Gitee 网站的
SSH keys
设置中添加相应的公钥
测试 SSH 连接
1 | ssh -T [email protected] |
测试结果:可以看到 SSH 已经连接成功
1 | Hi Lixx! You've successfully authenticated, but GitHub does not provide shell access. |
小结
- 本文分别在 GitHub 和 Gitee 上配置了不同的 SSH Key(当然也可以配置相同的 SSH Key), 在其他 Git 服务器配置更多 SSH Key 的操作也是类似的