配置gitee、github公钥

发布时间 2023-04-13 23:21:13作者: 咿呀喲
1.gitee 执行命令
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "邮箱"
2.github 执行命令
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "邮箱"
3.生成公钥后,可以在 C 盘的 .ssh 目录中查看,会生成 id_ras.gitee、id_ras.github 文件
4.到 gitee/github 中进行配置
5.测试通过 HTTPS 端口的 SSH 是否可行,执行命令
ssh -T -p 443 git@ssh.github.com
如果出现:Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access.说明可以通过 HTTPS 443端口建立的 SSH 连接
如果没有,需要去配置 config
6.若 .ssh 目录下有 config 文件,可以直接配置;若没有,执行命令生成 config 文件
touch ~/.ssh/config
7.将以下内容填入 config 文件中,IdentityFile 字段的值要是 .ssh 目录中的 github/gitee 公钥文件名
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.gitee
# github
Host github.com
Port 443
HostName ssh.github.com
User git
IdentityFile ~/.ssh/id_rsa.github
8.再次测试 SSH 是否可行,分别执行命令
ssh -T git@gitee.com ssh -T git@github.com
如果出现:Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access.表示配置成功