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?

【ConoHa VPS】PermitRootLogin noに変更してもrootユーザーでログインできてしまい、困った

0
Last updated at Posted at 2025-12-17

趣味で VPS を使おうとして、そんなところで!?という詰まり方をしたので自戒の意味も込めてメモです。

環境
  • ConoHa VPS CentOS Stream9(64bit)
$ cat /etc/redhat-release
CentOS Stream release 9

$ ssh -V
OpenSSH_8.7p1, OpenSSL 3.0.7 1 Nov 2022

やりたいこと

root ユーザーでログインできないようにしたい

やったこと

$ sudo vim /etc/ssh/sshd_config

初期状態だとコメントアウトされていたので、有効にしてから no へ書き換え

/etc/ssh/sshd_config
- #PermitRootLogin prohibit-password
+ PermitRootLogin no

変更した設定を読み込むため、サービスを再起動

$ sudo systemctl restart sshd

自分のローカル PC から、root ユーザーでログインできるか試す → ログインできてしまった…!

$ ssh root@xxx.xxx.xxx.xxx

解決方法

/etc/ssh/sshd_config.d 配下にある設定が優先されるらしい
※この中で PermitRootLogin yes に上書きされていたようだ

デフォルトで存在しているファイルは変更しない方がよいと/etc/ssh/sshd_config 内に記載されていた(見てなかった)

/etc/ssh/sshd_config
# To modify the system-wide sshd configuration, create a  *.conf  file under
#  /etc/ssh/sshd_config.d/  which will be automatically included below
Include /etc/ssh/sshd_config.d/*.conf

システム全体の sshd 設定を変更するには、以下の場所に *.conf ファイルを作成します。
/etc/ssh/sshd_config.d/

ので、sshd_config を一旦戻す

$ sudo vim /etc/ssh/sshd_config
/etc/ssh/sshd_config
- PermitRootLogin no
+ #PermitRootLogin prohibit-password

01-permitrootlogin.conf というファイルが存在しており、こちらで設定しているようだったので編集(なければ自分で作成する)

$ sudo vim /etc/ssh/sshd_config.d/01-permitrootlogin.conf
/etc/ssh/sshd_config.d/01-permitrootlogin.conf
- PermitRootLogin yes
+ PermitRootLogin no

再起動

$ sudo systemctl restart sshd

もう一度ローカル PC から、root ユーザーでログインを試みる → ログインできなくなった OK

$ ssh root@xxx.xxx.xxx.xxx
root@xxx.xxx.xxx.xxx's password: 
Permission denied, please try again.

おわりに

  • 説明文が書かれていたらちゃんと読もう!

参考URL

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?