sshdでパスワードログインを禁止する

こんなの簡単かと思いきや、はまってしまった。

とりあえずこれでOK

#/etc/ssh/sshd_config
PasswordAuthentication no
ChallengeResponseAuthentication no
KbdInteractiveAuthentication no
UsePAM Yes

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'.

sshd_configを変更したらsshdを再起動する必要がある。

参考にしたのはこちら hoge.sub.jp

ちょっと問題があったやり方

PAMを使いたくなかったので、UsePAM noPasswordAuthentication noを設定した。

#/etc/ssh/sshd_config
PasswordAuthentication no
UsePAM no

この設定(UsePAM no)だとパスワードログインは禁止できるのだが、 パスワードを設定していないユーザーが鍵認証でログインできなくなる。

PAMってなんなのですか。 web.archive.org

2021年12月25日追記

KbdInteractiveAuthentication noは当初入れていなかったのだが、入れるようにした。 ChallengeResponseAuthentication noとの違いがよくわからないがとりあえず入れておく。 ↓の説明を読んでもよくわからない。 www.kunitake.org