一. 發現問題:
使用 git clone 命令時出現Permission denied (public key) 。
二. 解決問題:
1、首先嘗試重新添加以前生成的key,添加多次,仍然不起作用。
2、使用命令 ssh -v git@github.com測試,最后幾行結果如下:
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個private key,但都沒有成功,最后是導致Permission denied.
4、查看我的密鑰, ls ~/.ssh/ :
bajie bajie.pub known_hosts
5、發現我的id_rsa文件我命令為bajie, 所以根本沒有使用它。同時可以使用如下命令查看密鑰列表:
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測試連接,可以看到驗證通過:
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項目成功。
歡迎訪問我的個人主頁: www.forgerui.tk