【Git】错误:权限被拒绝(公钥)(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

测试命令:

$ 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/*/.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).

在这里插入图片描述

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


解决方案:

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

测试命令

$ 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
  • 10
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: 出现"git@gitcode.net: Permission denied (publickey)"的错误提示是因为你在尝试连接到gitcode.net时,没有正确的访问权限或者没有正确的密钥。这可能是由于以下几个原因导致的:\[1\]\[2\]\[3\] 1. 你没有正确的访问权限。请确保你有正确的访问权限,并且你的账户被授权访问gitcode.net。 2. 你没有正确的密钥。请确保你的密钥正确配置,并且与gitcode.net上的账户关联。 3. 仓库不存在。请确保你要访问的仓库在gitcode.net上存在。 如果你确定你有正确的访问权限和密钥,并且仓库也存在,但仍然遇到这个问题,你可以尝试以下解决方法: 1. 检查你的密钥配置是否正确,并确保你的密钥与gitcode.net上的账户关联。 2. 确保你的账户被授权访问gitcode.net上的仓库。 3. 检查你的网络连接是否正常,并尝试重新连接。 如果问题仍然存在,建议你联系gitcode.net的技术支持或管理员,以获取进一步的帮助和解决方案。 #### 引用[.reference_title] - *1* [git提示 permission denied (publickey)问题的解决方法](https://blog.csdn.net/qq_36667170/article/details/100894172)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [gitcode 提交代码,遇到 Permission denied (publickey). 如何解决](https://blog.csdn.net/aomeng/article/details/128419531)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [【Git错误权限拒绝公钥)(Permission denied (publickey).)](https://blog.csdn.net/weixin_42282187/article/details/124820546)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值