git 无法使用ssh协议连接
一. 发现问题:
使用 git clone 命令时出现Permission denied (public key) 。
二. 解决问题:
1、首先尝试重新添加以前生成的key,添加多次,仍然不起作用。
2、使用命令 ssh -v git@yourserver 测试,最后几行结果如下:
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/ :
id_rsa id_rsa.pub known_hosts
5、
执行ssh-add ~/.ssh/rsa
报错(Could not open a connection to your authentication agent)
先执行 eval `ssh-agent` (是~键上的那个`) 再执行 ssh-add ~/.ssh/rsa成功
ssh-add -l 就有新加的rsa了
2048 63:c5:d8:6c:a0:0c:a8:9c:26:d8:f8:95:de:29:04:eb /home/gr/.ssh/bajie (RSA)
6、再使用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).
注释:如果是gitlab,提示不一样,但是可以明显看出连接成功
7、最后git clone项目成功。
参考博客:
https://my.oschina.net/grnick/blog/201155
http://blog.csdn.net/roserose0002/article/details/40078577
http://blog.csdn.net/sunnypotter/article/details/18948053/
更多推荐
所有评论(0)