Permission denied (publickey). fatal: Could not read from remote repository.
博主在github上下載tiny face的的源代碼的時(shí)候沈矿,遇到git clone命令為:git clone --recursive git@github.com:peiyunh/tiny.git
而當(dāng)我在ternimal下執(zhí)行這條語句的時(shí)候,出現(xiàn)錯(cuò)誤:
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.這時(shí)候再在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
這時(shí)候應(yīng)該會提示:
Identity?added: ...(這里是一些ssh key文件路徑的信息)
(注意)如果出現(xiàn)錯(cuò)誤提示:
Could?not?open?a?connection?to?your?authentication?agent.?
請執(zhí)行命令:eval?`ssh-agent?-s`后繼續(xù)執(zhí)行命令?ssh-add?~/.ssh/id_rsa媳溺,這時(shí)候一般沒問題啦月幌。
5.打開你剛剛生成的id_rsa.pub,將里面的內(nèi)容復(fù)制悬蔽,進(jìn)入你的github賬號扯躺,在settings下,SSH and GPG keys下new SSH key,title隨便取一個(gè)名字录语,然后將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.?
這時(shí)候你的問題就解決啦,可以使用命令 git clone --recursive git@github.com:peiyunh/tiny.git 去下載你的代碼啦盖袭。
原文鏈接:https://www.cnblogs.com/wmr95/p/7852832.html