問題描述:
執(zhí)行
git push origin master
提示 :
Permission denied (publickey).
fatal: Could not read from remote respository.
查到資料http://stackoverflow.com/questions/19660744/git-push-permission-denied-public-key,按照Eric Leschinski的步驟往下走。但是有依舊報錯我碟。究其原因上真,是最后兩步cat ~/.ssh/id_rsa.pub和ssh -T git@github.com沒有生效。
解決辦法:
1茫孔,將連接方式從http更換為ssh。注意,github.com后面一定有(冒號):
git remote rm origin
git remote add origingit@github.com:username/respository.git
2毁习,生成新的ssh key。這里會提示要不要rewrite卖丸,鍵入y纺且,還有提示輸入passPhrase,輸入空格即可稍浆。
cd ~/.ssh
ssh-keygen
3载碌,測試一下連接。
ssh -T -v git@github.com
不出意外的話這里會報錯衅枫,最后幾行提示信息如下:
debug1: Offering RSA public key: yourpath/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key:yourpath/.ssh/id_dsa
debug1: Trying private key:yourpath/.ssh/id_ecdsa
debug1: Trying private key:yourpath/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
提示信息表明路徑 yourpath/.ssh下id_rsa文件存在嫁艇,并且提供public key,然而無法和網(wǎng)站中的ssh-key匹配上为鳄。于是程序轉(zhuǎn)而尋找yourpath/.ssh路徑下的id_dsa文件裳仆,id_ecdsa文件,id_ed25519文件孤钦,看它們是不是能提供新的public key歧斟。
查看一下yourpath/.ssh,會發(fā)現(xiàn)下面根本不存在id_dsa偏形,id_ecdsa静袖,id_ed25519文件。 出錯的原因其實在于步驟4更新了本地的ssh key俊扭,然而網(wǎng)站上的ssh key還為舊值队橙,所以匹配不上,就報錯Permission denied (publickey)
4,打開yourpath/.ssh/id_rsa.pub(.pub為公鑰文件捐康,id_rsa為私鑰文件)仇矾,復制里面的內(nèi)容。
5解总,打開https://github.com/settings/profile贮匕,在SSH key那欄選擇New SSH Key,并將復制內(nèi)容拷貝到其中花枫,選擇保存刻盐。
6,再次測試$ ssh -T git@github.com劳翰,提示
You've successfully authenticated, but GitHub does not provide shell access.
錯誤排查完畢 _