こんなの簡単かと思いきや、はまってしまった。
とりあえずこれでOK
#/etc/ssh/sshd_config
PasswordAuthentication no
ChallengeResponseAuthentication no
KbdInteractiveAuthentication no
UsePAM yes
sshd_configを変更したらsshdを再起動する必要がある。
参考にしたのはこちら hoge.sub.jp
UsePAM yesは事実上必須
当初PAMを使いたくなかったので、UsePAM noとPasswordAuthentication noだけを設定した。
#/etc/ssh/sshd_config
PasswordAuthentication no
UsePAM no
この設定(UsePAM no)だとパスワードログインは禁止できるのだが、
パスワードを設定していないユーザーが鍵認証でログインできなくなる。
UsePAMについては、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 ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'.
PAMってなんなのですか。 web.archive.org
2021年12月25日追記
KbdInteractiveAuthentication noは当初入れていなかったのだが追加した。ChallengeResponseAuthentication noとの違いがわからないが、どうも冗長な設定項目らしい。
↓の説明を読んでもよくわからないが、両方ともnoにするのが無難なようだ。
www.kunitake.org
