エラーメッセージ
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 を使う方式にしか対応していません。
発生する理由
古い SSH クライアントやライブラリが ssh-rsa で署名している
よくある7.2 より前の OpenSSH、2.9 より前の Paramiko(Ansible の paramiko 接続プラグインの内部でも使われています)、オリジナルの JSch 0.1.55(Jenkins のプラグインや IDE)、古い golang.org/x/crypto、多くのネットワーク機器は、`ssh-rsa` 署名しか生成しません。
サーバーがアルゴリズムをさらに制限している
ときどきセキュリティ強化ガイドでは、`PubkeyAcceptedAlgorithms` を短いリスト(たとえば Ed25519 と ECDSA のみ)に設定しています。そのリストに含まれない RSA や Ed25519 の鍵は拒否されます。`ssh-ed25519` を含む別表記のエラーがその例です。
DSA 鍵
ときどき`ssh-dss` は OpenSSH 7.0 以降無効になっており、10.0 で削除されました。DSA 鍵は置き換えなければなりません。
修正方法
- 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.
やむを得ない場合は ssh-rsa を限定的に許可する
1 台のレガシー機器に限定した `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
関連するエラー
Permission denied (publickey).OpenSSH client (ssh, scp, sftp, git over SSH)Unable to negotiate with 127.0.0.1 port 22: no matching host key type found. Th…OpenSSH client (8.8+) connecting to a server that only offers legacy host key algorithmsssh: handshake failed: ssh: unable to authenticate, attempted methods [none pub…golang.org/x/crypto/ssh (Go)