git clone失败-Permission denied (publickey)

一、问题:

使用git clone [email protected]:xxxx/Vue.git无法clone远程仓库代码到本地,显示以下错误信息:

Warning: Permanently added the RSA host key for IP address '13.229.188.59' to th                e list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
二、原因:

由于在我们本地(或者服务器上)没有生成ssh key

三、解决方案:

执行cd ~/.ssh,查看是否有以下三个文件:

image.png

如果没有,按以下步骤执行命令:
1、ssh-keygen -t rsa -C "[email protected]"
[email protected]是github关联的邮箱地址,
如果之前有那三个文件请选择覆盖overwrite,执行后如图:

image.png

2、ssh -v [email protected]
执行后最后会出现以下提示:

image.png

3、ssh-agent -s

image.png

4、ssh-add ~/.ssh/id_rsa
①提示:Identity added: ......
②如果是错误提示:
错误提示.png

执行以下两个命令:
注意:eval 'ssh-agent' (注意要带上``符号,是~键上的那个`

eval 'ssh-agent -s'
ssh-add ~/.ssh/id_rsa

image.png

5、打开新生成的id_rsa.pub,将里面的内容复制到路径:github>setting>SSH and GPG keys下,选择“new key”;将id_rsa.pub内容复制到key中,最后Add SSH Key。
6、验证Key
ssh -T [email protected]
出现以下提示说明已经验证通过了,这时候可以git clone仓库代码了;
image.png

你可能感兴趣的:(git clone失败-Permission denied (publickey))