總結(jié)一下兑障,出現(xiàn)這個(gè)問(wèn)題原因是clone的時(shí)候需要使用一個(gè)公鑰和本地的私鑰來(lái)做身份認(rèn)證侄非。
1蕉汪、首先確認(rèn)自己有沒(méi)有g(shù)it帳號(hào)
2、有的話(huà)逞怨,生成一對(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) 到你賬戶(hù)的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)目成功。