密鑰格式不正確!!
複製 .pub
文件裏的密鑰 (利用 cat
命令查看)
如何生成密鑰?
ssh-keygen -t rsa -C "xxx" # xxx爲GitHub上註冊的郵箱
- Enter file in which to save the key: 選擇生成的 key 存放的位置(如果直接回車則選擇它括號中默認的路徑)
- Enter passphrase / Enter same passphrase again: 輸入密碼(可不填,直接回車就行)
然後你就能看見一個框起來還挺好看的 RSA,說明密鑰已經生成。直接去剛剛選擇的路徑中查看複製密鑰就行~
密鑰已經在 GitHub 添加成功了,git clone
的時候報錯:
[email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
原因:你本機的 git 倉庫並沒有和這個 SSH key 關聯上。
解決方法:
ssh-add 你的id-rsa文件地址
⚠️注意這裏
ssh-add
後面填的是私鑰地址,如 mac 電腦是/Users/用戶名/.ssh/id_rsa
add 之後可以用 ssh [email protected]
驗證是不是添加成功。