项目场景:
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
测试命令:
$ 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).
原因分析:
相同配置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
那为什么这台机器不能用呢,到底是哪里出了问题?好奇心驱动,继续寻找。经过百度发现GitHub SSH故障排除方法。
图片链接地址
检查使用的密钥:发现找到私钥文件debug1: Offering public key: /c/Users/hoomi/.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/hoomi/.ssh/config
debug1: /c/Users/hoomi/.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/hoomi/.ssh/id_rsa type 0
debug1: identity file /c/Users/hoomi/.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/hoomi/.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/hoomi/.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/hoomi/.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/hoomi/.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/hoomi/.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).
图片链接地址
解决方案:
config配置文件添加PubkeyAcceptedKeyTypes +ssh-rsa
修改后配置文件如下文章来源:https://www.toymoban.com/news/detail-520969.html
# 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
测试命令文章来源地址https://www.toymoban.com/news/detail-520969.html
$ 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
到了这里,关于【Git】错误:权限被拒绝(公钥)(Permission denied (publickey).)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!