
圖片.jpg
今天在github上看到一個比較感興趣的項(xiàng)目,于是想下載研究一下,CheckOut時拋了以下異常

圖片.jpg
git@github.com: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
原因分析
Permission denied (publickey) 沒有權(quán)限的publickey ,出現(xiàn)這錯誤一般是以下兩種原因
- 客戶端與服務(wù)端未生成 ssh key
- 客戶端與服務(wù)端的ssh key不匹配
找到問題的原因了,解決辦法也就有了,重新生成一次ssh key ,服務(wù)端也重新配置一次即可。
客戶端生成ssh key
ssh-keygen -t rsa -C "youremail@example.com"
youremail@example.com改為自己的郵箱即可,途中會讓你輸入密碼啥的,不需要管,一路回車即可,會生成你的ssh key。(如果重新生成的話會覆蓋之前的ssh key。)

圖片.jpg
然后再終端下執(zhí)行命令:
ssh -v git@github.com
最后兩句會出現(xiàn)
No more authentication methods to try.
Permission denied (publickey).
在終端再執(zhí)行以下命令
ssh-agent -s

圖片.jpg
接著在執(zhí)行
ssh-add ~/.ssh/id_rsa

圖片.jpg
Identity added: ...這是ssh key文件路徑的信息
配置服務(wù)端
打開你剛剛生成的id_rsa.pub,將里面的內(nèi)容復(fù)制,進(jìn)入你的github賬號,在settings下,SSH and GPG keys下new SSH key,然后將id_rsa.pub里的內(nèi)容復(fù)制到Key中,完成后Add SSH Key。

圖片.jpg
驗(yàn)證Key
ssh -T git@github.com

圖片.jpg
提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. 問題就解決啦