我成功将 Debian 11 升级到 Debian 12
一件奇怪的事情正在发生
我有一个conf来覆盖一些设置
我禁用了 root 登录
移至端口 1122
禁用使用密码进行身份验证
使用密钥启用身份验证
root@localhost:/etc/ssh/ssh_config.d# cat /etc/ssh/sshd_config.d/realtebo.conf # Override from realtebo Port 1122 PermitRootLogin no PasswordAuthentication no PubkeyAuthentication yes
现在我
- 必须使用端口 1122
- 无法使用 root 登录
- 可以使用密码登录
- 无法使用 pubkey 登录
是什么导致了这两种奇怪的行为?
我已经确保主配置文件包含我的。
无论如何,如果我直接更改主配置文件[我想避免],服务器不允许再使用密码登录,但仍然拒绝我的公钥,我检查了,。仍然在,authorized_keys
也是我在所有 Debian 11 上使用的 rsa pub 密钥。
Debian 12 中的 OpenSSH 发生了哪些变化?
答案1
- 可以使用密码登录
在主/etc/ssh/sshd_config
文件中,有一条注释:
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes
如果您的配置未禁用KbdInteractiveAuthentication
,它允许 PAM 通过稍微不同的代码路径执行相当于密码身份验证的操作,该代码路径最初用于质询/响应类型身份验证模块...但从技术上讲,“显示密码提示”可能是一个挑战,并“输入有效密码”对其进行有效响应。
默认配置应包含未注释的KbdInteractiveAuthentication no
,但请尝试
diff -u /usr/share/openssh/sshd_config /etc/ssh/sshd_config
仔细检查您当前的主sshd
配置文件是否确实与默认配置文件匹配。
另请注意,禁用密码身份验证时的默认行为sshd
是仍显示密码提示。在这种情况下,提示将完全是假的,其唯一目的是让入侵者浪费时间徒劳地尝试猜测密码。因此,如果您看到密码提示,并不一定意味着密码身份验证实际上可用。
如果您觉得这没有用,您可以添加AuthenticationMethods publickey
到您的帐户realtebo.conf
以阻止sshd
甚至提供任何密码提示(无论是假的还是真实的)。
- 无法使用 pubkey 登录
新版本具有新的默认 PubkeyAcceptedAlgorithms 设置。虽然很长,但更值得注意的是不包括(引自man sshd_config
):
公钥接受算法
[...]
该选项的默认值是:
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], ssh-ed25519, ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521, [email protected], [email protected], rsa-sha2-512,rsa-sha2-256
特别是旧的备用机,ssh-rsa
并且ssh-dss
,默认情况下不再存在。如果需要,您仍然可以添加它们,并且在您的情况下,添加可能会有所帮助...但如果是这种情况,您确实应该将 SSH 客户端更新到支持公钥算法ssh-rsa
的版本。rsa-sha2-*
您现有的密钥很好,只是它所使用的算法需要升级。
因此,您可以尝试将两个设置添加到您的/etc/ssh/sshd_config.d/realtebo.conf
:
KbdInteractiveAuthentication no
PubkeyAcceptedAlgorithms +ssh-rsa
如果此后 pubkey 身份验证仍然不起作用,请使用journalctl -u ssh.service
查看记录的消息sshd
来了解它拒绝您的公钥的确切原因。
(是的,运行的服务名称sshd
确实是ssh.service
Debian 及其衍生产品中的名称,而不是sshd.service
RHEL/Fedora 及其衍生产品中的名称。历史原因。愚蠢,但这就是生活。)
sshd
请注意,您可以通过运行查看有效配置sshd -T
。如果您的配置包含任何Match
条件,您可以添加-C keyword=value
样式选项来提供这些条件的必要信息,以检查条件匹配如何影响每种情况下的有效配置。请参阅man sshd
了解更多详情。