Permission denied (publickey). fatal: Could not read from remote repository.

Permission denied (publickey). fatal: Could not read from remote repository.

是新手常見的錯誤

 

博主在github上下載tiny face的的源代碼的時候,遇到git clone命令爲:git clone --recursive [email protected]:peiyunh/tiny.git

  而當我在ternimal下執行這條語句的時候,出現錯誤:

  Permissiondenied (publickey).

  fatal:Could not read from remote repository.

  Pleasemake sure you have the correct access rights

  and the repository exists.

  但是其實執行命令:git clone [email protected]:peiyunh/tiny.git 是沒有問題的(不加--recursive參數),於是百度了一番,我理解的是原因是由於你在本地(或者服務器上)沒有生成ssh key,你可以在ternimal下執行:

  cd ~/.ssh ls來查看是否有文件id_rsa以及文件id_rsa.pub,如下圖所示:(我的已經生成了,所以我ls後會顯示。)

 

 

下面記錄下解決辦法:

 

1.首先,如果你沒有ssh key的話,在ternimal下輸入命令:ssh-keygen -t rsa -C "[email protected]", [email protected]改爲自己的郵箱即可,途中會讓你輸入密碼啥的,不需要管,一路回車即可,會生成你的ssh key。(如果重新生成的話會覆蓋之前的ssh key。)

  

  2.然後再ternimal下執行命令:

  ssh -v [email protected] 

  最後兩句會出現:

  No more authentication methods to try.  

  Permission denied (publickey).

  3.這時候再在ternimal下輸入:

  ssh-agent -s

  然後會提示類似的信息:

  SSH_AUTH_SOCK=/tmp/ssh-GTpABX1a05qH/agent.404; export SSH_AUTH_SOCK;  

  SSH_AGENT_PID=13144; export SSH_AGENT_PID;  

  echo Agent pid 13144;

  4.接着再輸入:

  ssh-add ~/.ssh/id_rsa

  這時候應該會提示:

  Identity added: ...(這裏是一些ssh key文件路徑的信息)

  (注意)如果出現錯誤提示:

  Could not open a connection to your authentication agent.

  請執行命令:eval `ssh-agent -s`後繼續執行命令 ssh-add ~/.ssh/id_rsa,這時候一般沒問題啦。

  5.打開你剛剛生成的id_rsa.pub,將裏面的 全部內容複製,全部都要複製進入你的github賬號,在settings下,SSH and GPG keys下new SSH key,title隨便取一個名字,然後將id_rsa.pub裏的內容複製到Key中,完成後Add SSH Key。

  6.最後一步,驗證Key

  在ternimal下輸入命令:

  ssh -T [email protected]

  提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell  access.

  這時候你的問題就解決啦,可以使用命令 git clone --recursive [email protected]:peiyunh/tiny.git 去下載你的代碼啦。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章