[email protected]: Permission denied (publickey)

问题记录

git clone github仓库代码时,出现以下bug:

$  git clone [email protected]:ximury/vue.git
Cloning into 'vue'...
The authenticity of host '[ssh.github.com]:443 ([18.138.202.180]:443)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443,[18.138.202.180]:443' (RSA) to the 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.

在这里插入图片描述

再次尝试后,就是这种情况:

$  git clone [email protected]:ximury/vue.git
Cloning into 'vue'...
[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目录下生成一个github的SSH-Key时,自定义了文件名,如下:

$ ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github_id_rsa

然后就将.pub文件复制粘贴到github网站上的SSH keys中。

之后直接进行clone代码,就出现了以上BUG。

问题解决

方式一

使用命令 ssh-keygen -t rsa 直接生成默认的rsa文件,之后在github上配置pub即可

方式二

生成rsa文件时自定义文件名,需要在 .ssh 目录下添加一个config文件,样例如下:

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

注意: 其中 Host 和 HostName 后填写 git 服务器的域名,IdentityFile 指定私钥的路径(只需要修改 IdentityFile )

测试成功与否

ssh -T [email protected]

如果成功:

Hi ***! You've successfully authenticated, but GitHub does not provide shell access.

在这里插入图片描述

如果测试结果失败:

Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'C:\\Users\\wyj/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "C:\\Users\\wyj/.ssh/id_rsa": bad permissions
[email protected]: Permission denied (publickey).

在这里插入图片描述

执行下面命令制定目标Git账号:

ssh-add -k id_rsa

id_rsa文件对应之前生成的rsa文件

之后再执行测试命令即可!

在这里插入图片描述

Last

最后,附上成功的截图:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/WU2629409421perfect/article/details/112306305
今日推荐