前言:
在使用 gitee 过程中 gitee 报错
克隆不了远程仓库,同步 github 代码也失败
push也不成功
使用gitee 进行push 时报错(报错信息如下)
: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
查看ssh文件
在桌面 点击鼠标右键 (Git Bash here) -> cd 进入 .ssh 文件夹 如下图
注意:如果没有该文件夹,自己 C 盘的 用户路径下 新建 .ssh 文件夹
ls 命令检查是否存在 SSH Key
cd ~/.ssh
ls
删除之前的.ssh
生成gitee和github 的 SSH Key
1. ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_github"
2. ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_gitee"
配置github的SSH key
输入自己的邮箱后一直回车,即可出现以下画面
查看SSH Key
cat id_rsa_github.pub // 这里是查看 github的 SSH Key
拷贝 ssh-rsa 开头的 ssh key,然后到github上添加ssh key
右键头像,下面有个 Setting,在里面配置 ssh
自己取一个名字,把刚才命令行复制的ssh 粘贴在下面,点击添加
配置gitee的 ssh key
操作和上面的类似,只是把命令换成了
ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_gitee" // 生成gitee 的 SSH Key
cat id_rsa_gitee.pub // 这里是查看 gitee 的 SSH Key (这里注意和 github 区分一下)
然后把生成的 ssh key 复制到 gitee,进行添加 ssh key 操作,(操作类似上面的 github 添加 ssh)
添加 config解决ssh冲突
在 .ssh 文件夹路径下
执行命令:vi config
在这里面一个一个输入比较慢,所以先退出,先按键盘的 Esc,输入“ :wq ”,回车退出
然后 C盘 的.shh 文件夹中 找到 并打开 config 文件,将下面的内容复制进 config 文件,保存即可
# 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
注意:
上面这个是关键的一步,一定要新创config文件解决ssh冲突
测试是否配置成功
ssh -T [email protected]
ssh -T [email protected]
输入命令,出现下面类似的结果即配置成功
注意
可能会出现下面的内容 (直接输入 yes 即可正常连接)
The authenticity of host 'gitee.com (212.64.63.190)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])
总结:
本文章主要介绍 Git 同时配置 github和 gitee 的ssh key 的相关步骤
最重要的是要新建 config 文件 解决 ssh冲突
文章是关于 git 的初级内容,文章如有错误,恳请大家提出问题,本人不胜感激
文章对大家有帮助的话,希望大家能动手点赞鼓励,未来一起努力 长路漫漫,道阻且长
转载请注明出处:https://blog.csdn.net/qq_52855464/article/details/124890091?spm=1001.2014.3001.5501