升级Fedora 33后,ssh出现“Permission denied(publickey)”错误

14

我一直在尝试很多与我现在提出的问题类似的Stackoverflow答案,但仍然无法解决我的问题。 我正在尝试通过ssh克隆,但始终收到Permission denied (publickey)错误。

当我运行命令GIT_SSH_COMMAND="ssh -vvv" git clone git@bitbucket.org:myusername/my-api.git 时。

debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
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: kex: curve25519-sha256@libssh.org need=64 dh_need=64
debug1: kex: curve25519-sha256@libssh.org need=64 dh_need=64
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ssh-rsa SHA256:kkXQOXSRBEiUtuE8AikLLLwbHaxvSc0ojez9YXaGp2A
debug3: hostkeys_foreach: reading file "/home/alienwarepocket/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/alienwarepocket/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from bitbucket.org
debug3: hostkeys_foreach: reading file "/home/alienwarepocket/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/alienwarepocket/.ssh/known_hosts:3
debug3: load_hostkeys: loaded 1 keys from 18.205.93.2
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /home/alienwarepocket/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/alienwarepocket/.ssh/id_rsa RSA SHA256:ktMzaalYyvU9Ev1bgELXatabkUkdcT828O0PppnNiV4M explicit agent
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/alienwarepocket/.ssh/id_rsa RSA SHA256:ktMzaalYyvU9Ev1bgELXatabkUkdcT828O0PppnNiV4M explicit agent
debug1: send_pubkey_test: no mutual signature algorithm
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

在将 Fedora 33 升级后,我遇到了这个问题,在 Fedora 32 上没有出现这个问题。


我猜测由于新安装,您的公钥已更改。您可以尝试通过https克隆吗? - Peaceful
2
这是来自 Fedora 33 的一个 bug,我在 Reddit 上发现了它,有人问了同样的错误 @Peaceful。 - Pocket
1
不是一个错误 - Fedora 33 现在坚决反对弱加密。 - Jetski S-type
你之前已经接受了正确的答案。 - VonC
我已经编辑了我的答案,包括update-crypto-policies --set DEFAULT:FEDORA32命令(这是我最初提到的链接的一部分)。 - VonC
显示剩余2条评论
3个回答

33
这可能与Fedora33中的“Changes/StrongCryptoSettings2”有关。
默认策略的更改如下: - 仅保留TLS 1.2(有时可用的TLS 1.3)作为启用的协议,并将TLS 1.x,x ≤ 1移至遗留级别。 - 要求在默认设置中使用2048或更多的有限场参数(RSA、Diffie-Hellman)。 - 禁用SHA1签名支持(X.509证书、TLS、IPSEC握手)。
上述链接中的“Upgrade/compatibility impact”部分清楚地说明了影响升级和兼容性的内容。

It may be that the new settings break software that connects to servers which utilize weak algorithms.
Compatibility can be obtained by switching the system to Fedora 32 policy level:

update-crypto-policies --set DEFAULT:FEDORA32

不推荐使用,如果可以使用ed25519,则更好。

Peque答案中所述,您可以在~/.ssh/config中添加一个选项,最初在sshd_config中找到

 PubkeyAcceptedKeyTypes
         Specifies the key types that will be accepted for public key
         authentication as a list of comma-separated patterns.

因此,如果您无法使用ed25519,您可以针对特定主机允许使用id_rsa密钥:

Host aHost
    Hostname a.hostname.com
    PubkeyAcceptedKeyTypes +ssh-rsa

最后:升级后请仔细检查您的权限:

  • ~/.ssh775 drwxrwxr-x
  • ~/.ssh/id_rsa600 -rw-------
  • ~/.ssh/id_rsa.pub644 -rw-r--r--
  • ~/.ssh/config600 -rw-------
  • 远程服务器上的~/.ssh/authorized_keys600 -rw-------

但现在似乎推荐使用ssh-keygen -t ed25519生成密钥。


设置默认值,如以前的 Fedora 一样,这是不推荐的,因为 Fedora 33 中的新功能更加安全。 - Pocket
@Pocket 是的,我刚刚编辑了答案,明确指出这不是建议做法。 - VonC
6
使用ssh-keygen -t ed25519重新生成密钥,解决了我在bitbucket.org上的问题。 - Creak
谢谢你的解决方案!请在描述中添加“~/.ssh/config”文件权限应为600。 - Alexander Arutinyants
1
@AlexanderArutinyants 很好的观点。我已经相应地编辑了答案。 - VonC

12

@VonC是正确的,我升级到Fedora 33后遇到了这个权限问题。

运行以下命令可以解决:

update-crypto-policies --set DEFAULT:FEDORA32

感谢您分享那篇文章。


2
我升级到 Fedora 33,遇到了同样的问题。当使用 Bitbucket 存储库时,这个解决方案对我有效。 - ant2009
这个解决方案在 Fedora 33 上对我有效,使用了 GitLab 上的仓库。 - Bruno Morais
要明确的是,这个解决方案表示“我可以使用弱加密”,而VonC的解决方案修复了根本问题,并使用强加密使Fedora 33满意。 - Jetski S-type
最好使用PubkeyAcceptedKeyTypes=+ssh-rsa来针对需要的服务器进行设置,而不是全局更改策略。此内容来源于https://stackoverflow.com/a/65007312/520567。 - akostadinov

9

不要全局更改加密策略,最好针对每个主机降低安全级别。

您可以通过在.ssh/config文件中添加以下内容来更新特定旧版主机的配置:

Host legacy.host
    PubkeyAcceptedKeyTypes +ssh-rsa

想了解更多详情,请查看在Bugzilla上的讨论


我跟着链接走了,谢谢,它有 PubkeyAcceptedKeyTypes ssh-rsa - 所以略有不同,但在 Fedora 34 上对我有效。 - colin0117

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接