Fedora 27
Sponsored Link

Sudo の設定2017/12/13

 
root 権限の委譲や権限の分離、root パスワードの使いまわし防止のため Sudo を設定しておきます。
なお、Sudo は最小構成インストールでもデフォルト構成に含まれているため、新たにインストールする必要はありません。
[1] root 権限を特定のユーザーに全て委譲する。
[root@dlp ~]#
# 最終行に追記: fedoraはroot権限を全て利用できる

fedora  ALL=(ALL)       ALL
# 書式 ⇒ 委譲先 ホスト=(委譲元) コマンド
# ユーザー [fedora] で動作確認

[fedora@dlp ~]$
/bin/cat /etc/shadow

cat: /etc/shadow: Permission denied    
# 正常に拒否される
[fedora@dlp ~]$
sudo /bin/cat /etc/shadow

Password:    
# 自身のパスワード
tcpdump:!!:16973::::::
systemd-coredump:!!:16973::::::    
# 実行できた
[2] [1]の設定に加えて、しかし、特定のコマンドは許可しない。
[root@dlp ~]#
# 適当に49行目あたりに追記: システム停止系のコマンドエイリアス追記

Cmnd_Alias SHUTDOWN = /sbin/halt, /sbin/shutdown, \
/sbin/poweroff, /sbin/reboot, /sbin/init, /bin/systemctl
# [1] の設定部分に追記 ( エイリアス [SHUTDOWN] は許可しない )

fedora     ALL=(ALL)     ALL,
!SHUTDOWN
# ユーザー [fedora] で動作確認

[fedora@dlp ~]$
sudo /sbin/shutdown -r now

Password:
Sorry, user fedora is not allowed to execute '/sbin/shutdown -r now' as root on dlp.srv.world.    
# 拒否された
[3] root 権限が必要な特定のコマンドを特定のグループに属するユーザーに委譲する。
[root@dlp ~]#
# 適当に51行目あたりに追記: ユーザー管理系のコマンドエイリアス追記

Cmnd_Alias USERMGR = /sbin/useradd, /sbin/userdel, /sbin/usermod, \
/bin/passwd
# 最終行: グループ [usermgr] に属するユーザーに [USERMGR] で定義したコマンド許可設定追記

%usermgr ALL=(ALL) USERMGR
[root@dlp ~]#
groupadd usermgr

[root@dlp ~]#
usermod -G usermgr fedora

# ユーザー [fedora] で動作確認

[fedora@dlp ~]$
sudo /sbin/useradd testuser

[fedora@dlp ~]$    
# 正常に完了

[fedora@dlp ~]$
sudo /bin/passwd testuser

Changing password for user testuser.
New UNIX password:    
# testuserのパスワード設定

Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[4] root 権限が必要な特定のコマンドを特定のユーザーに委譲する。
[root@dlp ~]#
# 最終行: それぞれのユーザーに特定のコマンドの許可設定追記

fedora  ALL=(ALL)       /sbin/visudo
cent    ALL=(ALL)       /sbin/useradd, /sbin/userdel, /sbin/usermod, /bin/passwd
ubuntu  ALL=(ALL)       /bin/vi

# ユーザー [fedora] で動作確認

[fedora@dlp ~]$
sudo /sbin/visudo
# 正常に開き保存編集もできる

## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
# ユーザー [cent] で動作確認

[cent@dlp ~]$
sudo /sbin/userdel -r testuser

[cent@dlp ~]$    
# 正常に完了
# ユーザー [ubuntu] で動作確認

[ubuntu@dlp ~]$
sudo /bin/vi /boot/grub2/grub.cfg
# 正常に開き保存編集もできる

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
[5] デフォルトでは /var/log/secure に sudo の実行ログが残りますが、sudo のログを別ファイルに記録したい場合は以下のように設定します。
[root@dlp ~]#
# 最終行に追記

# 例として、ファシリティ [local1] にログを出力する

Defaults syslog=local1
[root@dlp ~]#
vi /etc/rsyslog.conf
# 46,47行目: 追記

*.info;mail.none;authpriv.none;cron.none;local1.none   /var/log/messages
local1.*                /var/log/sudo.log

# The authpriv file has restricted access.
authpriv.*              /var/log/secure

[root@dlp ~]#
systemctl restart rsyslog

関連コンテンツ