問題
Github克隆項目的時候報如下錯:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
從上面報出的錯誤提示可以知道在克隆項目時沒有權限所以被拒絕了,Github 服務器和我們本地的通訊要使用 SSH key(密鑰)來驗證,去我們Github主頁檢查是否缺少密鑰,缺少了密鑰只需設置一個密鑰就行了。
解決方法
從Github主頁右上角點擊頭像選擇Settings,點擊進入SSH and GPG keys
點擊創建一個新的密鑰"New SSH key"
SSH Key獲取方法
打開 Git Base,輸入命令:ssh-keygen -t rsa -C ‘emailXXXX@example.com’,然后一直回車,注意:有y/n是輸入y,下圖中這個y/n就是已經有文件項目詢問是否覆蓋的意思。
接下來輸入命令:cat ~/.ssh/id_rsa.pub
這個時候顯示出密鑰,然后直接復制密鑰粘貼到GitHub設置密鑰SSH的key上面然后保存即可。