跳到主要内容
ecdsa.com
OpenSSH server (sshd) logSSH

错误信息

userauth_pubkey: signature algorithm ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

也可能输出为

  • userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
  • userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedKeyTypes [preauth]
  • userauth_pubkey: signature algorithm ssh-ed25519 not in PubkeyAcceptedAlgorithms [preauth]

各 sshd 版本的措辞(已对照 OpenSSH 源代码核实):9.0 及更高版本为“signature algorithm … not in PubkeyAcceptedAlgorithms”;8.5~8.9 为“key type … not in PubkeyAcceptedAlgorithms”;8.4 及更早版本为“key type … not in PubkeyAcceptedKeyTypes”(该选项在 8.5 中改了名)。消息中的算法取决于客户端以及服务器的限制。

OpenSSH server (sshd) log — the client sees only "Permission denied (publickey)."

含义

服务器日志中的这条消息解释了客户端看到的“Permission denied (publickey)”:客户端提供的签名算法不被服务器接受。如果是 `ssh-rsa`,那就是基于 SHA-1 的 RSA 签名方案,自 OpenSSH 8.8(2021年)起默认禁用。RSA 密钥本身没有问题——同一个密钥配合 `rsa-sha2-256`/`rsa-sha2-512` 算法就能正常使用——但客户端(旧版 OpenSSH、过时的库或嵌入式设备)只支持 SHA-1 这一变体。

原因

修复方法

  1. 1.

    改用现代密钥或现代客户端

    Ed25519 密钥可以彻底避开 RSA/SHA-1 问题;否则就更新客户端库,让它能协商 `rsa-sha2-*`。

    bash
    # Best: a modern key type, which every current client signs correctly
    ssh-keygen -t ed25519 -C "deploy@ci" -f ~/.ssh/deploy_ed25519
    # Or keep the RSA key and use a client that supports rsa-sha2-256/512
    # (OpenSSH >= 7.2, Paramiko >= 2.9, JSch fork 0.2.x, golang.org/x/crypto >= 2022, PuTTY >= 0.75)
  2. 2.

    如果确有必要,只在最小范围内允许 ssh-rsa

    只为某一台老旧设备单独写一个 `Match` 块,其他所有客户端仍然不允许使用 SHA-1 签名。只把它当作临时措施。

    text
    # /etc/ssh/sshd_config.d/legacy-device.conf - only for one legacy client, and remove it afterwards
    Match Address 10.0.5.17
        PubkeyAcceptedAlgorithms +ssh-rsa

相关错误

浏览完整的签名错误库