原文: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_rsa
和id_rsa.pub
添加祕鑰
在github上添加ssh密鑰,這要添加的是id_rsa.pub
裏面的公鑰
在github官網,點擊頭像->Settings->SSH and GPG keys->New SSH key,添加公鑰即可
添加公鑰之後,就可以從github正常拉取代碼了