首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >理解ssh-rsa而不是PubkeyAcceptedAlgorithms

理解ssh-rsa而不是PubkeyAcceptedAlgorithms
EN

Security用户
提问于 2023-05-21 20:03:09
回答 1查看 688关注 0票数 4

从运行El Capitan的旧Mac计算机连接到Amazon实例时,我遇到了问题。不幸的是,没有任何可能升级的操作系统。

因为我拥有的所有其他现代设备都可以使用相同的键连接到实例,因此我认为这个问题与ssh客户端与服务器交互的方式有关,特别是由于旧的ssh客户端版本。

私钥是由EC2控制台生成的。

因此,我在服务器端进行了一些调试,发现了以下消息:

代码语言:javascript
复制
userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

然后,我分析了服务器端的authorized_keys文件,发现如下:

代码语言:javascript
复制
cat ~/.ssh/authorized_keys
ssh-rsa <long string> mykey-rsa

首先,我想知道为什么如果密钥被标记为ssh-rsa,服务器就会拒绝这样的选项。

因此,我使用-vvv选项对机器进行ssh,以便从输出中获取此片段:

代码语言:javascript
复制
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
    ....
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512
debug2: kex_parse_kexinit: ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
debug2: kex_parse_kexinit: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
debug2: kex_parse_kexinit: hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512
debug2: kex_parse_kexinit: hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com

如果我没有错,第一部分中的条目是来自客户端的选项,而其他部分则来自服务器端。事实上,我可以看到ssh-rsa只在客户端可用。所以我认为选择一个普通的algoritm就可以解决这个问题:

代码语言:javascript
复制
ssh -l ec2-user myserver -i .ssh/ec2-key.pem  -vvvvvv -oKexAlgorithms=curve25519-sha256@libssh.org

但是,在服务器端,我再次看到了同样的错误:

代码语言:javascript
复制
userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

我错过了什么?

我知道我可以通过在服务器端授权ssh-rsa来解决这个问题,但我更感兴趣的是了解正在发生的事情。

更新

按照建议的方法(我标记为已被接受),我选择了选项2,因为在这样的代码级别升级旧的MacOS并不容易,也可能很危险。

EC2密钥对控制台提供了两个选项: RSA和ED25519,我选择了一个带有'ED25519‘的密钥,并替换了授权密钥文件中的相关公钥,现在我可以连接到实例了。

EN

回答 1

Security用户

回答已采纳

发布于 2023-05-21 23:15:13

ssh-rsa这个名字在这里有两个不同的含义。

有键类型ssh-rsa,您可以在authorized_keys文件的第一列中看到它。RSA密钥非常好并且得到了广泛的支持。

但是,也有签名算法ssh-rsa,它代表使用SHA-1哈希算法的RSA签名。因为SHA-1是不安全的,OpenSSH禁用ssh-rsa自8.8版以来的签名算法。现在,预期SSH客户端和服务器将使用rsa-sha2-256 (带有SHA-256的RSA签名)或rsa-sha2-512 (具有SHA-512的RSA签名)。

要解决这个问题,有三种选择:

  • 更新SSH客户端,以便可以使用更新的签名算法。这是迄今为止最好的解决办法。如果您无法通过操作系统获得当前的OpenSSH版本,请独立安装OpenSSH。
  • 使用ECDSA类型(例如ecdsa-sha2-nistp256)或EdDSA创建一个新的SSH密钥,而不是RSA。然后您可以绕过签名算法问题。
  • 如果由于某种奇怪的原因,您不能这样做,那么最后的办法是通过将ssh-rsa签名算法添加到PubkeyAcceptedAlgorithms上,在服务器上启用它。请注意,这是一个安全风险。
票数 10
EN
页面原文内容由Security提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://security.stackexchange.com/questions/270349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档