sshd:“没有主机密钥 alg”已修复但仍然很困惑

sshd:“没有主机密钥 alg”已修复但仍然很困惑

显然 Fedora 35 没有在 HostKeyAlgorithms 或 PubkeyAcceptedKeyTypes 中列出 ssh-rsa,因此尝试从旧的 CentOS 6 机器进行 ssh 会产生错误:

$ ssh as1s16.intra.corp.us
no hostkey alg

所以我在 /etc/ssh/sshd_config 中的 Include 之后添加了选项:

Include /etc/ssh/sshd_config.d/*.conf

HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa

但同样的错误。然后我像这样运行 sshd:

# /usr/sbin/sshd -ddd
...
debug3: /etc/ssh/sshd_config:20 setting HostKeyAlgorithms +ssh-rsa
debug3: /etc/ssh/sshd_config:21 setting PubkeyAcceptedKeyTypes +ssh-rsa
...
debug1: SELinux support disabled [preauth]
...
debug3: append_hostkey_type: ssh-rsa key not permitted by HostkeyAlgorithms [preauth]
debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]

但同样的错误。然后我删除了运行 sshd 的选项,如下所示:

# /usr/sbin/sshd -ddd -oHostKeyAlgorithms=ssh-rsa

它起作用了。我能够从 CentOS 6 客户端成功 ssh 登录。

然后我将选项放在包含之前:

HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa

# To modify the system-wide sshd configuration, create a  *.conf  file under
#  /etc/ssh/sshd_config.d/  which will be automatically included below
Include /etc/ssh/sshd_config.d/*.conf

它起作用了。

为什么我需要将这些指令放在 Include 之前?难道他们不应该去覆盖默认值吗?

答案1

尽管该措辞不是很清楚,但我怀疑该config.d/*目录允许为特定客户端/用户或传入接口/端口使用单独的配置文件,而不是“系统范围”。这类似于sites/*apache/httpd 和 nginx(可能还有更多)中目录的使用,允许单独配置每个虚拟主机或应用程序,但仍然由一台服务器支持。查看那些文件查看它们是否包含匹配行(后面应该跟其他实际行=不匹配、注释或空白),这意味着它们仅适用于某些连接而不是全部。

包括是文本的。如果你有一个文件

blich
Include file*
blech

其中 blich 和 blech 不包含匹配行,但至少有一些文件执行此操作,然后 blech 有效地成为文件串联中最后一个 Match 块的一部分 - 因此 blech 中的设置仅用于满足这些 Match 条件的传入连接,您的测试连接显然没有。

如果您希望 SSHD 设置为“全局”,则必须将它们放在任何匹配行之前,并且如果包含的文件包含匹配行,则意味着您必须将全局设置放在之前包括。

配置文件中的所有(使用的)设置都会覆盖程序中的默认设置。在配置文件中多次放置相同的设置(在任何 Match 块之前/之外)使用第一的一个不是最后一个,因此您覆盖较早的“默认值”(如果它在文件中的话根本不是默认值)的想法是行不通的。仅当后面出现的匹配块中的条件满足时,它才会覆盖第一个匹配块。

PS:这可能是现在发生的,因为 Fedora 是最前沿的并且OpenSSH 最近终于改变了这一点在警告(威胁?)之后,他们从一年半前的 8.2 开始就会这样做。

答案2

我用了:

HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa

在 /etc/ssh/sshd_config 中并重新启动 sshd。

相关内容