LoginSignup
7
9

More than 5 years have passed since last update.

Ubuntuでsshのrootログインを禁止する

Last updated at Posted at 2016-02-28

Ubuntu 14.04で構築し、sshのrootログインを禁止する方法です。
※公開鍵でのログインはまた別途か追記します。とりあえずパスワードログインまで。

ユーザ作成

ユーザを追加する。

$ adduser UserName
Adding user `UserName' ...
Adding new group `UserName' (1000) ...
Adding new user `UserName' (1000) with group `UserName' ...
Creating home directory `/home/UserName' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for UserName
Enter the new value, or press ENTER for the default
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] y

wheelグループを作成する。

$ groupadd wheel

wheelグループをsudoできるようにする。

$ visudo

#以下の一行を追加。
%wheel  ALL=(ALL) ALL

sudoを実行した際に、「sudo: unable to resolve host xxx-xxx-xxx-xxx」というメッセージが出る場合はhostsを編集。

$ sudo vim /etc/hosts

#以下の一行を追加。
127.0.0.1    xxx-xxx-xxx-xxx

rootログイン禁止の設定

rootログインを禁止する。

$ vim /etc/ssh/sshd_config

#yes→noに変更。
PermitRootLogin no

sshを再起動。

$ service ssh restart

rootでログインして入れないことを確認する。

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