Permission denied (publickey). fatal: Could not read from remote repository. - 王老頭 - 博客園
博主在github上下載tiny face的的源代碼的時候,遇到git clone命令為:git clone --recursive git@github.com:peiyunh/tiny.git
而當(dāng)我在ternimal下執(zhí)行這條語句的時候,出現(xiàn)錯誤:
Permissiondenied (publickey).
fatal:Could not read from remote repository.
Pleasemake sure you have the correct access rights
and the repository exists.
但是其實(shí)執(zhí)行命令:git clone git@github.com:peiyunh/tiny.git 是沒有問題的(不加--recursive參數(shù))辜贵,于是百度了一番店归,我理解的是原因是由于你在本地(或者服務(wù)器上)沒有生成ssh key挂脑,你可以在ternimal下執(zhí)行:
cd ~/.ssh ls來查看是否有文件id_rsa以及文件id_rsa.pub罗售,如下圖所示:(我的已經(jīng)生成了判族,所以我ls后會顯示。)
下面記錄下解決辦法:
1.首先旺垒,如果你沒有ssh key的話彩库,在ternimal下輸入命令:ssh-keygen -t rsa -C "youremail@example.com", youremail@example.com改為自己的郵箱即可先蒋,途中會讓你輸入密碼啥的骇钦,不需要管,一路回車即可竞漾,會生成你的ssh key眯搭。(如果重新生成的話會覆蓋之前的ssh key。)
2.然后再ternimal下執(zhí)行命令:
ssh -v git@github.com?
最后兩句會出現(xiàn):
No?more?authentication?methods?to?try.??
Permission?denied?(publickey).
3.這時候再在ternimal下輸入:
ssh-agent?-s
然后會提示類似的信息:
SSH_AUTH_SOCK=/tmp/ssh-GTpABX1a05qH/agent.404;?export?SSH_AUTH_SOCK;??
SSH_AGENT_PID=13144;?export?SSH_AGENT_PID;??
echo?Agent?pid?13144;
4.接著再輸入:
ssh-add?~/.ssh/id_rsa
這時候應(yīng)該會提示:
Identity?added: ...(這里是一些ssh key文件路徑的信息)
〕氩洹(注意)如果出現(xiàn)錯誤提示:
Could?not?open?a?connection?to?your?authentication?agent.
請執(zhí)行命令:eval?`ssh-agent?-s`后繼續(xù)執(zhí)行命令?ssh-add?~/.ssh/id_rsa坦仍,這時候一般沒問題啦。
5.打開你剛剛生成的id_rsa.pub叨襟,將里面的內(nèi)容復(fù)制繁扎,進(jìn)入你的github賬號,在settings下糊闽,SSH and GPG keys下new SSH key梳玫,title隨便取一個名字,然后將id_rsa.pub里的內(nèi)容復(fù)制到Key中右犹,完成后Add SSH Key提澎。
6.最后一步,驗(yàn)證Key
在ternimal下輸入命令:
ssh?-T?git@github.com
提示:Hi xxx!?You've?successfully?authenticated,?but?GitHub?does?not?provide?shell??access.
這時候你的問題就解決啦念链,可以使用命令 git clone --recursive git@github.com:peiyunh/tiny.git 去下載你的代碼啦盼忌。