0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PasswordAuthenticationをnoに設定したのに、パスワード認証が出来てしまう

Last updated at Posted at 2025-07-16

概要

PasswordAuthentication noを設定してsudo systemctl restart sshdを実行しているのにパスワードの入力が求められてしまう。

環境

  • raspberryPi上でUbuntuserverを動かしている
  • Ubuntu 25.04
  • OpenSSH_9.9p1 Ubuntu-3ubuntu3.1, OpenSSL 3.4.1 11 Feb 2025

結論

/etc/ssh/sshd_config.d/50-cloud-init.confの中に

PasswordAuthentication yes

という文字列が残っていた

PasswordAuthentication no

にすることで解決された。

hoge@hoge.hoge.hoge.hoge: Permission denied (publickey).と表示され想定通りの環境になった

解説

原因:Includeによる設定の上書き

/etc/ssh/sshd_config ファイルの中にこのような行がありました

Include /etc/ssh/sshd_config.d/*.conf

これは、「この位置で /etc/ssh/sshd_config.d/ フォルダ内の すべての .conf ファイル を読み込んで設定に適用する」という意味があるらしいです。

わたしの場合では
sshd_config の下部にこう書いていた:

PasswordAuthentication no

しかしファイルの冒頭に

Include /etc/ssh/sshd_config.d/*.conf

があった。

sshd_config.d/50-cloud-init.conf(場合よってファイル名が違うっぽい)にこう書かれていた:

PasswordAuthentication yes

この結果、「後から読み込まれた sshd_config.d/*.confPasswordAuthentication yes を有効化し、設定全体に影響した」ということらしい

訂正

ssh_config/sshd_configでは同じ設定項目が複数あった場合、先にある方が適用され、後ろの方は無視される。
今回の場合、sshd_configのInclude行でsshd_config.d/50-cloud-init.confが読み込まれてPasswordAuthentication yesが設定され、sshd_configの中で後ろにあるPasswordAuthentication noが無視される事になる。
なので、sshd_configのInclude行より前にPasswordAuthentication noを書いてあげるとsshd_config.d/50-cloud-init.confを書き換えずにパスワード認証を無効化できる。

0
0
2

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?