AlmaLinux9 启用 OpenSSH 后量子密钥交换

背景

从 OpenSSH 9.0 开始,默认引入了混合后量子密钥交换算法 sntrup761x25519-sha512@openssh.com,用于抵御“先存储,后解密”(store now, decrypt later)攻击。OpenSSH 9.9 新增了 mlkem768x25519-sha256,并在 OpenSSH 10.0 中成为新默认。

在AlmaLinux 9的最新版本,openssh已经升级到9.9,理论上应当支持后量子密钥交换算法,但是连接时依旧存在警告:

WARNING: connection is not using a post-quantum key exchange algorithm.
This session may be vulnerable to "store now, decrypt later" attacks.
The server may need to be upgraded. See https://openssh.com/pq.html

查看 sshd 实际生效的密钥交换算法

sshd -T | grep kexalgorithms

会发现输出中只有传统 ECDH 和 DH 算法。这是因为系统级加密策略 crypto-policies 会覆盖 OpenSSH 的默认算法列表,默认情况下 不包含任何后量子算法

服务器环境

  • AlmaLinux 9
  • OpenSSH 9.9
  • 已安装 crypto-policies(一般预装,如果没装显然也不会遇到这个问题了)以及 crypto-policies-scripts(提供 update-crypto-policies 命令)

验证 OpenSSH 版本:

sshd -V

确认已安装脚本包:

dnf install crypto-policies-scripts

问题排查回顾

  1. 查看当前系统加密策略

    update-crypto-policies --show

    默认输出为 DEFAULT

  2. 查看 sshd 实际生效的密钥交换算法

    sshd -T | grep kexalgorithms

    输出中只有传统 ECDH 和 DH 算法,缺少 sntrup761x25519-sha512@openssh.commlkem768x25519-sha256

  3. 查看 crypto-policies 生成的 SSH 后端文件

    cat /etc/crypto-policies/back-ends/opensshserver.config | grep KexAlgorithms

    同样不包含后量子算法,这就是警告的根本原因。

解决方案:启用系统自带的 PQ 子策略

AlmaLinux 9的 crypto-policies 包中已经预置了一个 后量子(PQ)子策略模块,路径为:

ls /usr/share/crypto-policies/policies/modules/PQ.pmod

那么要做的事情就很简单了,将 PQ 子策略附加到 DEFAULT 策略上(也可使用 FUTURE 等):

更新系统加密策略

update-crypto-policies --set DEFAULT:PQ

重启服务

systemctl restart sshd

验证生效

  1. 查看 sshd 当前提供的密钥交换算法

    sshd -T | grep kexalgorithms

    输出应包含 mlkem768x25519-sha256

  2. 查看 crypto-policies 后端文件确认

    cat /etc/crypto-policies/back-ends/opensshserver.config | grep KexAlgorithms

    同样应看到 mlkem768x25519-sha256

  3. 从客户端连接测试

    ssh your_server

    之前的 PQ 警告完全消失。

CC BY-NC-SA 4.0 Deed | 署名-非商业性使用-相同方式共享
最后更新时间:2026-05-31 22:06:23