git clone時(shí)出現(xiàn)Permission denied (public key)問(wèn)題解決

總結(jié)一下,出現(xiàn)這個(gè)問(wèn)題原因是clone的時(shí)候需要使用一個(gè)公鑰和本地的私鑰來(lái)做身份認(rèn)證。

1、首先確認(rèn)自己有沒(méi)有g(shù)it帳號(hào)

2、有的話,生成一對(duì)公私鑰對(duì),公鑰上傳到github,私鑰需要添加到本地的私鑰列表

具體步驟如下所示:

用?git clone?時(shí)出現(xiàn)錯(cuò)誤:

Permission?denied?(publickey).

上網(wǎng)搜了一下, 原因是'You've probably not added a public key to your SSH keys.'

解決方法如下:

用下面的命令生成public key

$ ssh-keygen -t rsa

復(fù)制 public key (id_rsa.pub) 到你賬戶的list of SSH keys, 再重新運(yùn)行clone命令

如果還不行,執(zhí)行下面的分析步驟:

1、首先嘗試重新添加以前生成的key,添加多次,仍然不起作用。

2、使用命令 ssh -v git@github.com測(cè)試,最后幾行結(jié)果如下:

debug1: Authentications that can continue: publickey

debug1: Next authentication method: publickey

debug1: Trying private key: /home/gr/.ssh/id_rsa

debug1: Trying private key: /home/gr/.ssh/id_dsa

debug1: Trying private key: /home/gr/.ssh/id_ecdsa

debug1: No more authentication methods to try.

Permission denied (publickey).

3、分析:嘗試了3個(gè)private key,但都沒(méi)有成功,最后是導(dǎo)致Permission denied.

4、查看我的密鑰, ls ~/.ssh/ :

bajie ?bajie.pub ?known_hosts

5、發(fā)現(xiàn)我的id_rsa文件我命令為bajie, 所以根本沒(méi)有使用它。同時(shí)可以使用如下命令查看密鑰列表:

ssh-add -l

6、上面命令的密鑰列表為空,所以要添加我的密鑰,使用命令:

gr@grpc:~/workspace/git/home$ ssh-add ~/.ssh/bajie

Enter passphrase for /home/gr/.ssh/bajie:

Identity added: /home/gr/.ssh/bajie (/home/gr/.ssh/bajie)

7、再次查看,如下,添加成功:

gr@grpc:~/workspace/git/home$ ssh-add -l

2048 63:c5:d8:6c:a0:0c:a8:9c:26:d8:f8:95:de:29:04:eb /home/gr/.ssh/bajie (RSA)

8、再使用ssh -v git@github.com測(cè)試連接,可以看到驗(yàn)證通過(guò):

debug1: Authentications that can continue: publickey

debug1: Next authentication method: publickey

debug1:Offering RSA public key: /home/gr/.ssh/bajie

debug1: Server accepts key: pkalg ssh-rsa blen 279

debug1:Authentication succeeded (publickey).

Authenticated to github.com ([192.30.252.129]:22).

9、最后git clone項(xiàng)目成功。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容