LoginSignup
0
0

macOSで/etc/ssh/sshd_configを書き換えてパスワード認証禁止にしてもリセットされる

Posted at

よくある解説とリセットされる設定

「ssh パスワード認証 禁止」でググるとよく出て来るのは、

sshd_config
PasswordAuthentication no
KbdInteractiveAuthentication no

sshd_configに書け、いうもの。自分も/etc/ssh/sshd_configをそのように書き換えていたのだが、ある日元に戻っていることに気付いた。「OSの更新でsshd_configがデフォルトに戻されたのかな」程度に考えていたのだが、毎回書き換えるのも面倒だ、ということで対処法を調べて見た。なお、OSはmacOS Sonoma(14.4.1)である。

原因

「元に戻ってしまう原因」はsshd_configがデフォルトに戻ってしまうこと。そりゃそうだ。戻ってしまうのは仕方無いので、「戻されても設定を維持できる方法」を調べよう。すると18行目に以下の記述があった。

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

うん、まあそうだよね。ちなみに/etc/ssh/sshd_config.d/には100-macos.confがあり、

100-macos.conf
# Options set by macOS that differ from the OpenSSH defaults.
UsePAM yes
AcceptEnv LANG LC_*
Subsystem	sftp	/usr/libexec/sftp-server

と書かれている。コメントにもある通り、OpenSSHのデフォルトとは異なるオプションを設定してある。このファイルを書き換えてもいいんだけど、100-macos.confがデフォルトに戻されるとまた面倒なので、新しいファイルを作る事にした。

/etc/ssh/sshd_config.d/999-nopasswordauth.conf
PasswordAuthentication no
KbdInteractiveAuthentication no

ファイル名は例なので、各自適当に変更すれば良いと思う。とりあえずこれで様子を見よう。

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