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