1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS VPSのrootログイン禁止設定

1
Last updated at Posted at 2019-11-10

SSHでのrootログインは危険

VPSでサーバーを立ち上げるとほとんどのサーバーでrootログインができるようになっています。

そうしないと、初期設定ができないので…。

サーバーを立ち上げたらまずはrootログインを禁止したいところです。

サーバー環境

代替のLinuxで同じことが可能ですが、下記の環境を前提としています。

  • サーバー:ConoHa VPS
  • OS:CentOS 7.7

root以外のユーザーからssh接続する

ログインユーザー作成

管理者ユーザー(srvadmin)を作成。名前は何でもOK。

# useradd srvadmin

パスワードを設定

# passwd srvadmin

管理者のwheelグループに追加

# usermod -aG wheel srvadmin

rootログインの禁止設定

wheelグループのみがroot昇格可能に。

# vi /etc/login.defs

以下の行を最終行に追加して変更を保存します。

/etc/login.defs
SU_WHEEL_ONLY yes

rootでのログインを禁止に。

# vi /etc/ssh/sshd_config
PermitRootLogin yes -> noに変更

SSHDのリスタート

# service sshd restart

おわり

以上です。簡単に終わると思います。
他にもSSHDのポートを22から変更する、パスワードではなく証明書でsshログインを許可するなどありますが、パスワードを10文字以上英数字大小+記号で組み合わせればそう簡単に破られるものではありません。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?