无法设置 SSH 密钥(PuTTY 到 Ubuntu 服务器)

无法设置 SSH 密钥(PuTTY 到 Ubuntu 服务器)

我在 Windows 11 上使用 PuTTY 连接到 Ubuntu Server 20.04.4。带密码的 SSH 连接有效,但当我尝试使用密钥连接时,我再次收到密码提示。我打开了登录功能,结果发现我的服务器不接受 RSA: mm_answer_keyallowed: publickey authentication test: RSA key is not allowed

我发现OpenSSH 8.8 默认不允许使用 RSA(SHA-1)密钥,虽然我不确定我的密钥是否是 SHA-1(PuTTY 有一个单独的SSH-1(RSA)我没有使用密钥类型,我使用了默认的RSA一)我尝试了不同的密钥类型(推荐的密钥类型之一)这里)。

我尝试生成 ECDSA 密钥只是为了得到结果mm_answer_keyallowed: publickey authentication test: ECDSA key is not allowed

以下是 RSA 密钥的示例:

debug1: trying public key file /home/wintermute/.ssh/authorized_keys
debug1: fd 5 clearing O_NONBLOCK
debug2: /home/wintermute/.ssh/authorized_keys:1: check options: '---- BEGIN SSH2 PUBLIC KEY ----\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:1: advance: 'BEGIN SSH2 PUBLIC KEY ----\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:2: check options: 'Comment: "rsa-key-20220310"\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:2: advance: '"rsa-key-20220310"\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:3: check options: 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCQskShaece0af5fHVTwPu/nFhDGwOoqxhP\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:3: advance: ''
debug2: /home/wintermute/.ssh/authorized_keys:4: check options: 'S/9h4URK6axdsae5Um3EWhiTFlNdukPHtDZ1ZCcO7n4zGB90NyNyszgZ4XGYpuCR\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:4: advance: ''
debug2: /home/wintermute/.ssh/authorized_keys:5: check options: '/JthkwXs9MmhAB+PYXeCnCsOyFtY9VkStvu8OuHmj9QJXAHlvukKHlpEh7yAD3Q6\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:5: advance: ''
debug2: /home/wintermute/.ssh/authorized_keys:6: check options: 'qkyD4LDbw4H+n9el98U4Lgah/xEuKCNFAwsYfZ2+hqFtvdwnARcqYRvQnSrbh6Cg\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:6: advance: ''
debug2: /home/wintermute/.ssh/authorized_keys:7: check options: 'l18vruoGn6oLCmDL5iWkgILJ+5l934p/NtemdJZBnXPvc1Whd1/MsrLzOt0tbStA\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:7: advance: ''
debug2: /home/wintermute/.ssh/authorized_keys:8: check options: 'JlabiywG87OgcaQ/yoIGTKmgjNtRvWscycq1RW+VWdW4wph6PT9L\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:8: advance: ''
debug2: /home/wintermute/.ssh/authorized_keys:9: check options: '---- END SSH2 PUBLIC KEY ----\r\n'
debug2: /home/wintermute/.ssh/authorized_keys:9: advance: 'END SSH2 PUBLIC KEY ----\r\n'
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/wintermute/.ssh/authorized_keys2
debug1: Could not open authorized keys '/home/wintermute/.ssh/authorized_keys2': No such file or directory
debug1: restore_uid: 0/0
debug3: mm_answer_keyallowed: publickey authentication test: RSA key is not allowed
Failed publickey for wintermute from 192.168.0.130 port 52984 ssh2: RSA SHA256:NhGXwSWgy7fV2KZ2p8B0RcxWr/qBwwG8RNUNo2EXrgc

我究竟做错了什么?

答案1

我发现 OpenSSH 8.8 默认不允许使用 RSA(SHA-1)密钥,尽管我不确定我的密钥是否是 SHA-1

不,它不允许签名使用 SHA-1 制作。没有专门的“SHA-1”或“SHA-2”在实际的 RSA 密钥中本身;可以使用相同的 RSA 密钥对两者进行签名。

“SSH-1 (RSA)”选项与 SHA 算法完全无关。SSHv1 是 SSH 协议的旧版本,已过时多年。(这有点像 SSLv2 与 TLSv1.3。)

debug2:/home/wintermute/.ssh/authorized_keys:1:检查选项:'---- BEGIN SSH2 PUBLIC KEY ----\r\n'

您以错误的格式将密钥添加到了文件中。您似乎在 PuTTYgen 中单击了“保存公钥”,这为您提供了一个 SSH.COM (RFC 4716) 格式的密钥,该格式例如由 Multinet SSH 使用,但是不是由 OpenSSH 提供。

相反,OpenSSH 的 authorized_keys 文件需要“一行”OpenSSH 格式,您可以从 PuTTYgen 文本框中获取该格式,其标题恰如其分地为“用于粘贴到 OpenSSH authorized_keys 文件中的公钥:”。

(两种格式中的实际密钥完全相同,只是格式不同。)

相关内容