LoginSignup
0
1

More than 1 year has passed since last update.

Ubuntu20 でユーザー追加、sudo設定、SSHのrootログイン禁止までの手順

Last updated at Posted at 2022-04-01

外部公開サーバーでは、sudo設定、SSHのrootログイン禁止は
セキュリティ上、必須な設定だと思われます。
恥ずかしながら、実は設定していなかった為、作業手順のまとめ

■ユーザー追加

①新規ユーザー追加
# adduser -c "Guest Add User" -d /home/userA -s /bin/bash userA

useradd -c "[コメント]" -d [ホームディレクトリ] -s [シェル] [ユーザー名]

②ユーザーパスワード設定
# passwd userA

passwd [ユーザー名]

■sudo設定

対象ユーザーを、「wheel」グループに追加

# usermod -G wheel userA

usermod -G wheel [ユーザー名]

「wheel」グループのユーザが「sudo」を利用できるように設定を変更
# visudo
↓以下の部分がコメントアウトされていなければ、コメントアウト
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
%wheel ALL=(ALL) ALL

■SSHのrootログインを禁止

設定ファイルの変更

# vi /etc/ssh/sshd_config

↓私の環境では、38行目

LoginGraceTime 15s
#PermitRootLogin yes
#StrictModes yes

↓以下のように設定変更

PermitRootLogin no

設定ファイルの保存後、構文チェック

# sshd -t

エラーにならないことを確認

sshdの設定反映 ※ !!以後ログオフした時点から、rootでログインできなくなるので注意!!
# systemctl restart sshd.service
※sshdログインユーザーは、以下のファイルで設定
①/etc/pam.d/sshd の設定
/etc/pam.d/sshd
account    required    pam_access.so  ## 11行目のコメントを外します
②/etc/security/access.conf の設定
/etc/security/access.conf
+ : user1 : 168.192.
+ : user2 : 172.0.0.
+ : user3 : ALL    ## 全てのIP

※↑但し、私の環境では、外部からの接続時、ファイアーウォールのIP=1つの処理になって
  しまう事が判明、このIP制御は機能しませんでした。
  (どの外部IPから来ても、=ファイアーウォールのIPと処理されていました。)

■WinSCPの追加設定

↓いざという時にWinSCPでの重要ファイルの操作が不便な為、WinSCPでも特定ユーザーで
root権限でのファイル閲覧編集を可能にする事に
WinSCPで特定ユーザーでもroot権限でファイル閲覧編集を可能にする方法


参考にさせていただいたページ

https://qiita.com/Zen-GoTo-May/items/3aab7b6c76e8a857e717
https://manual.sakura.ad.jp/vps/support/security/sudo.html
https://webkaru.net/linux/ssh-prohibit-root-login/
https://cloudpack.media/1101

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