克隆git代碼到本地時報“fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.”


克隆代碼時報錯:git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

怎么解決:

先查看當前的賬號和郵箱,

git config user.name

git config user.email

如果有誤的話可以切換用戶名和郵箱:

git config --global user.name "xxx"

git config --global user.email "xxx"

如果沒錯的話,很可能就是不同設備上的ssh公鑰不同,比如我有兩台電腦,其中git倉庫用的是其中一台電腦產生的ssh公鑰()但不同設備產生的公鑰是不能互用的,所以如果要克隆git上的代碼到另一台設備上,就需要讓另一台設備產生的公鑰也添加到git上

生成公鑰的命令:

ssh-keygen -t rsa -C "xxxxx@xxxxx.com" 
接下來終端顯示的內容就是需要你回車和輸入密碼了 中文翻譯 🔽 生成公共/私有rsa密鑰對 輸入保存密鑰的文件(/Users/jiangpeng/.ssh/id_rsa): /用戶/ jiangpeng /。ssh / id_rsa已經存在。 覆蓋(y / n) ?y (下面會讓你輸入密碼,我也不清楚,我隨意的輸入六位密碼) Enter passphrase (empty for no passphrase): Enter same passphrase again:


如果另一台設備已經生成了公鑰,那么再次執行生成公鑰的命令時,
就會提示是否覆蓋,選中否,然后在提示已有的公鑰路徑去找
一般是這個:

 

 

 

 在這個目錄下右鍵,git bush here

然后cat id_rsa.pub查看公鑰內容。然后復制下來。

在gitee中添加這個公鑰:

 

 之后就可以在指定目錄進行克隆目標倉庫了:git clone 倉庫路徑


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM