一、背景
在git 提交的时候,突然就行不通,一直报错:
-
Permission denied (publickey).
-
fatal: Could not read from remote repository.
-
-
Please make sure you have the correct access rights
-
and the repository exists.
二、解决方案
1、刚开始以为是配置的原因,因此初始化git config
-
git config -- list //查看当前的config配置
-
git config -- global user.name "youruser" //修改用户名
-
git config -- global user.email "你的邮箱" //修改为你的邮箱
这部分配置的是你个人的用户名称和电子邮件地址。这两条配置很重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,所以会随更新内容一起被永久纳入历史记录
关于git config,建议参考文档git config 文档
2、重新使用git pull 拉取数据,此时显示正常
三、git push 报错:
-
Access denied
-
exec request failed on channel 0
-
fatal: Could not read from remote repository.
-
-
Please make sure you have the correct access rights
-
and the repository exists.
1、先去看看.ssh有问题没
-
1、进入.ssh目录
-
cd ~/.ssh
-
2、查看此时下面的公钥私钥
-
ls //看看有没有 id_rsa id_rsa_pub 等文件
-
3、如果存在改文件,说明此时是配置好的。我们可以复制id_rsa_pub文件中的公钥,去码云上面,添加SSh公钥
如图所示从新添加个公钥试试。
2、继续git push
还是报错:
-
Access denied
-
exec request failed on channel 0
-
fatal: Could not read from remote repository.
-
-
Please make sure you have the correct access rights
-
and the repository exists.
这下ssh也没问题了,再报错,那是有八九还是配置的原因
1)进入git的配置文件所在
-
1、cd .git
-
2、vim config
2)着重查看url部分
就是箭头指向这里,我这边是因为url的问题。和码云上克隆的地址不一样,所以才造成提交失败。
路径改为一致的路径。此时执行git push,发现执行成功。
总体来说,这部分的内容还是挺多的,排错过程试了很多方法。大家遇到错误也多找找原因,有可能就是很简单的问题,但是却浪费我们大量的时间。
转载地址:https://blog.csdn.net/belalds/article/details/80485160