当前位置:   article > 正文

【Git】错误:权限被拒绝(公钥)(Permission denied (publickey).)

permission denied (publickey).

项目场景:

Git项目突然不能正常使用,自己的账号下的项目。提示Permission denied (publickey).


问题描述:

附上具体配置描述如下
.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
# codeup.aliyun
Host codeup.aliyun.com
HostName codeup.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/git_code_id_rsa
# coding.net
Host e.coding.net
HostName e.coding.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

测试命令:

$ ssh -T git@gitee.com
Hi **! You ve successfully authenticated, but GITEE.COM does not provide shell access.
$ ssh -T git@github.com
Hi **! You ve successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@codeup.aliyun.com
Welcome to Codeup, **!
$ ssh -T git@e.coding.net
git@e.coding.net: Permission denied (publickey).
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

原因分析:

相同配置3个成功,1个失败,不应该是git软件问题,应该是配置问题,在mac上进行相同配置一气呵成一切都是那么完美。

 ~  ssh -T git@e.coding.net
CODING 提示: Hello **, You've connected to coding.net via SSH. This is a Personal Key.
**,你好,你已经通过 SSH 协议认证 coding.net 服务,这是一个个人公钥.
公钥指纹:94:db:5f:c3:87:fb:f7:e5:da:9b:4f:0c:8e:35:ef:2b
  • 1
  • 2
  • 3
  • 4

那为什么这台机器不能用呢,到底是哪里出了问题?好奇心驱动,继续寻找。经过百度发现GitHub SSH故障排除方法。
在这里插入图片描述
图片链接地址
检查使用的密钥:发现找到私钥文件debug1: Offering public key: /c/Users/*/.ssh/id_rsa RSA 错误信息为签名错误no mutual signature algorithm,原因是OpenSSH从8.8版本由于安全原因开始弃用了rsa加密的密钥

$ ssh -Tv git@e.coding.net
OpenSSH_8.9p1, OpenSSL 1.1.1n  15 Mar 2022
debug1: Reading configuration data /c/Users/*/.ssh/config
debug1: /c/Users/*/.ssh/config line 17: Applying options for e.coding.net
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to e.coding.net [81.69.155.167] port 22.
debug1: Connection established.
debug1: identity file /c/Users/*/.ssh/id_rsa type 0
debug1: identity file /c/Users/*/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.9
debug1: Remote protocol version 2.0, remote software version Go-CodingGit
debug1: compat_banner: no match: Go-CodingGit
debug1: Authenticating to e.coding.net:22 as 'git'
debug1: load_hostkeys: fopen /c/Users/*/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-rsa SHA256:jok3FH7q5LJ6qvE7iPNehBgXRw51ErE77S0Dn+Vg/Ik
debug1: load_hostkeys: fopen /c/Users/*/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'e.coding.net' is known and matches the RSA host key.
debug1: Found key in /c/Users/*/.ssh/known_hosts:9
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/*/.ssh/id_rsa RSA SHA256:/jsxB0H9in7p9/U81BTwArpeQiX4OAKGxlHqL8qnzMI explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/*/.ssh/id_rsa RSA SHA256:/jsxB0H9in7p9/U81BTwArpeQiX4OAKGxlHqL8qnzMI explicit
debug1: send_pubkey_test: no mutual signature algorithm
debug1: No more authentication methods to try.
git@e.coding.net: Permission denied (publickey).

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

在这里插入图片描述

在这里插入图片描述
图片链接地址


解决方案:

config配置文件添加PubkeyAcceptedKeyTypes +ssh-rsa修改后配置文件如下

# 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
# codeup.aliyun
Host codeup.aliyun.com
HostName codeup.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/git_code_id_rsa
# coding.net
Host e.coding.net
HostName e.coding.net
PreferredAuthentications publickey
PubkeyAcceptedKeyTypes +ssh-rsa
IdentityFile ~/.ssh/id_rsa
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

测试命令

$ ssh -T git@e.coding.net
CODING 提示: Hello **, You've connected to coding.net via SSH. This is a Personal Key.
**,你好,你已经通过 SSH 协议认证 coding.net 服务,这是一个个人公钥.
公钥指纹:94:db:5f:c3:87:fb:f7:e5:da:9b:4f:0c:8e:35:ef:2b
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/963588
推荐阅读
相关标签
  

闽ICP备14008679号