LoginSignup
1
1

【RHEL9】Teratermで作ったRSA鍵が公開鍵認証で使えない

Posted at

概要

普段の手順でやろうと思ったらうまくいかなかったのでメモ

なにが起きているか

なぜかTeratermで作成したRSA鍵で公開鍵認証しようとしたら繋がらない
「認証に失敗しました。再試行してください」というメッセージが出て認証できない。

サーバー側のログを確認してみたところ、何やら出ていた

/var/log/secure
userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

「ssh-rsaは対応してないからダメだよ!」みたいなメッセージが。
どうやらSHA1メッセージダイジェスト鍵がRHEL9ではデフォルトで禁止されているらしい。

PubkeyAcceptedAlgorithmsはssh_configの設定で、受け入れる暗号化アルゴリズムを設定する。
sshd_configのmanを見てみると、基本的には「crypto-policiesの設定に準拠するよ」と記載がある。

PubkeyAcceptedAlgorithms
The default is handled system-wide by crypto-policies(7). Information about defaults, how to modify the defaults and how to customize existing policies with sub-policies are present in manual page update-crypto-policies(8).

Specifies the signature algorithms that will be accepted for public key authentication as a list of comma-separated patterns. Alternately if the specified list begins with a ‘+’ character, then the specified algorithms will be appended to the built-
in openssh default set instead of replacing them. If the specified list begins with a ‘-’ character, then the specified algorithms (including wildcards) will be removed from the built-in openssh default set instead of replacing them. If the speci‐
fied list begins with a ‘^’ character, then the specified algorithms will be placed at the head of the built-in openssh default set.

crypto-policiesはLinuxシステムでの暗号化アルゴリズムの設定を管理する仕組みらしい。
見た感じ、/etc/crypto-policies/back-ends/openssh.configの設定を参照している?

# cat /etc/crypto-policies/back-ends/openssh.config | grep "PubkeyAcceptedAlgorithms"
PubkeyAcceptedAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com

ここを見る感じ、「ssh-rsa」の記載がないので、
RHEL9のOpenSSHはcrypto-policiesの設定引っ張られてssh-rsaでの公開鍵認証ができないものと思う。

Teratermはrsa-sha2-256/512に対応していないらしい

今更ssh-rsa?とか思って調べてたら、どうもTeratermはrsa-sha2-256/512に対応していないらしい。

Teraterm4系も対応していないみたいなので、Teratermで作ったRSA鍵では公開鍵認証できないということ。

解決策

ED25519で鍵を作る

RSA鍵にこだわりがなければED25519で鍵を作り直す。
こちらであればTeratermから作った鍵でも問題なく公開鍵認証できました。

サーバー側をssh-rsaに対応させる(基本的には非推奨)

crypto-policiesかsshd_configの設定でssh-rsaに対応させることも可能。
ただし、安全ではない行為なので真似しないように。

crypto-policiesで設定
SHA1に対応させるようにする。

# update-crypto-policies --set DEFAULT:SHA1
# cat /etc/crypto-policies/back-ends/openssh.config | grep "PubkeyAcceptedAlgorithms" | grep "ssh-rsa"
PubkeyAcceptedAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com

「ssh-rsa」が設定に増えていることがわかる。
元に戻す場合は下記コマンドから。

# update-crypto-policies --set DEFAULT:NO-SHA1
# cat /etc/crypto-policies/back-ends/openssh.config | grep "PubkeyAcceptedAlgorithms" | grep "ssh-rsa"
>> 結果が帰ってこない

sshd_configで設定
設定に下記を追加

sshd_config
PubkeyAcceptedAlgorithms=+ssh-rsa.

beta版のteratermで鍵を作る

まだbeta版だが、ver5ならrsa-sha2-256/512に対応しているようなので、
こっちを使ってもいいと思う。(筆者はまだやっていない)

おわり

エラーメッセージもそうだけど、manページも読むことは大切だなぁ、と。
結構細かいことたくさん書いているのでとても参考になる。
英語しんどいけど・・・

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1