git pull 报错:权限不够 Permission denied


一、背景

在git 提交的时候,突然就行不通,一直报错:

  1.  
    Permission denied (publickey).
  2.  
    fatal: Could not read from remote repository.
  3.  
     
  4.  
    Please make sure you have the correct access rights
  5.  
    and the repository exists.

二、解决方案

1、刚开始以为是配置的原因,因此初始化git config

  1.  
    git config -- list //查看当前的config配置
  2.  
    git config -- global user.name "youruser" //修改用户名
  3.  
    git config -- global user.email "你的邮箱" //修改为你的邮箱

这部分配置的是你个人的用户名称和电子邮件地址。这两条配置很重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,所以会随更新内容一起被永久纳入历史记录

关于git config,建议参考文档git config 文档

2、重新使用git pull 拉取数据,此时显示正常

三、git push 报错:

  1.  
    Access denied
  2.  
    exec request failed on channel 0
  3.  
    fatal: Could not read from remote repository.
  4.  
     
  5.  
    Please make sure you have the correct access rights
  6.  
    and the repository exists.

1、先去看看.ssh有问题没

  1.  
    1、进入.ssh目录
  2.  
    cd ~/.ssh
  3.  
    2、查看此时下面的公钥私钥
  4.  
    ls //看看有没有 id_rsa id_rsa_pub 等文件
  5.  
    3、如果存在改文件,说明此时是配置好的。我们可以复制id_rsa_pub文件中的公钥,去码云上面,添加SSh公钥

这里写图片描述
如图所示从新添加个公钥试试。

2、继续git push

还是报错:

  1.  
    Access denied
  2.  
    exec request failed on channel 0
  3.  
    fatal: Could not read from remote repository.
  4.  
     
  5.  
    Please make sure you have the correct access rights
  6.  
    and the repository exists.

这下ssh也没问题了,再报错,那是有八九还是配置的原因

1)进入git的配置文件所在

  1.  
    1、cd .git
  2.  
    2、vim config

2)着重查看url部分

这里写图片描述

就是箭头指向这里,我这边是因为url的问题。和码云上克隆的地址不一样,所以才造成提交失败。 

 

路径改为一致的路径。此时执行git push,发现执行成功。

总体来说,这部分的内容还是挺多的,排错过程试了很多方法。大家遇到错误也多找找原因,有可能就是很简单的问题,但是却浪费我们大量的时间。

转载地址:https://blog.csdn.net/belalds/article/details/80485160


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM