git clone報錯:Permission denied (publickey). fatal: Could not read from remote repository...

原文:git clone報錯:Permission denied (publickey). fatal: Could not read from remote repository…

今天clone一份github代碼,報錯:

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

Please make sure you have the correct access rights
and the repository exists.

查了資料發現是因爲本機的publickey沒有添加到github(因爲剛剛重裝了系統),之前一直以爲訪問公開庫沒有添加公鑰的要求,這波才知道原來只要是clone github代碼就需要添加公鑰

祕鑰生成

ssh-keygen -t rsa -C "youremail"

密碼不用設置,直接回車即可。完成後在 ~/.ssh 目錄生成兩個文件:id_rsaid_rsa.pub

添加祕鑰

在github上添加ssh密鑰,這要添加的是id_rsa.pub裏面的公鑰
在github官網,點擊頭像->Settings->SSH and GPG keys->New SSH key,添加公鑰即可
image.png
添加公鑰之後,就可以從github正常拉取代碼了

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