LPIC あずき本v5.0 ch12 セキュリティ 12.2
- ユーザーに対するセキュリティ管理
- This file MUST be edited with the 'visudo' command as root.
- Please consider adding local content in /etc/sudoers.d/ instead of
- directly modifying this file.
- システムリソースの制限
ユーザーに対するセキュリティ管理
パスワード管理
chage
- パスワードに有効期限を設定
- パスワード変更を強制する
- アカウントの期限も設定できる
- オプション
-l アカウント名
,--list アカウント名
- パスワードもしくはアカウントの有効期限表示
-m 最低間隔日数
,--mindays 最低間隔日数
- パスワード変更間隔の最低日数を設定
-M 最大有効期限日数
,--maxdays 最大有効期限日数
- パスワードの最大有効期限日数を設定
-d 最終更新日
,--lastday 最終更新日
- パスワードの最終更新日を設定
-W 有効期限切れ日数
,--warndays 有効期限切れ日数
- パスワードの有効期限切れの警告が何日前から始まるかを設定
-I 有効期限切れ後、使用不能になるまでの日数
,--inactive 有効期限切れ後、使用不能になるまでの日数
- パスワードの有効期限後にアカウントがロックされるまでの日数を設定
-E アカウントを無効化する日付
,--expiredate アカウントを無効化する日付
- ユーザーアカウントが無効になる日付を設定
- 作りたてのユーザのパスワード情報(
/etc/shadow
)
hoge:$6$jcst/7zn$ZGb7frxHB5ie2l33ev4lbdSfAAIF.xFRpgVnr2OsxptvXH4wKIUPGEpdCo7cWbMzGnuxXhnAsMmawKQvNpNiV.:18001:0:99999:7:::
sudo chage -m 3 -M 28 -W 7 -I 0 -E 2019-12-31 hoge
- 同じパスワードを3日は使わせる
- パスワードは4週間有効
- 3週間たつと警告が出始める(28-7=21日)
- パスワード有効期限切れ後、アカウント即ロック
/etc/shadow
ファイルにおいて、暗号化パスワードの先頭に!
がつくのかな多分
- アカウント自体は2019年いっぱい使える
hoge:$6$jcst/7zn$ZGb7frxHB5ie2l33ev4lbdSfAAIF.xFRpgVnr2OsxptvXH4wKIUPGEpdCo7cWbMzGnuxXhnAsMmawKQvNpNiV.:18001:3:28:7:0:18261:
- 日付は
1970-01-01
からの日数で格納されるよう - 対話型でも設定できる
sudo chage hoge
- 設定確認
sudo chage --list hoge
最終パスワード変更日 : 4月 15, 2019 パスワード期限: : 5月 13, 2019 パスワード無効化中 : 5月 13, 2019 アカウント期限切れ : 12月 31, 2019 パスワードが変更できるまでの最短日数 : 3 パスワードを変更しなくてよい最長日数 : 28 パスワード期限が切れる前に警告される日数 : 7
ログインの禁止
/etc/nologin
- rootアカウントでコンソールログインを行うだけのシステムでは一般ユーザのログインは不要
- このファイルがあるとroot以外でのログインを禁止できる
sudo touch /etc/nologin
/bin/false
,/sbin/nologin
- ログインさせない用のシェル
- ユーザーアカウントは必要だが、ユーザーがログインしてシェルを利用するのは好ましくないケースで使用
- メールサーバ, FTPサーバ等
sudo usermod -s /sbin/nologin hoge
/etc/passwd
直接編集、またはvipw
コマンドで書き換えても良い
ユーザーの切り替え
- 常時rootで作業するな
- 普段は一般ユーザ、権限が必要なときだけroot
su
- 一時的に別ユーザになる
su - hoge パスワード: <hogeのパスワード入力>
ディレクトリがありません。HOME=/ としてログインします
pwd
/
- exitで元のユーザに戻る
exit
su hoge pwd exit
/home/wand/Desktop/learn/lpic
- ユーザ名指定なし: rootユーザに変更
sudo
- 特定の管理者コマンドのみの実行を許可
su | sudo | |
---|---|---|
認証 | rootのパスワード | sudo実行者のパスワード |
認可 | exitするまでなんでも | 指定のコマンドのみ |
sudo
の設定
/etc/sudoers
ファイルで設定- 直接開かない
This file MUST be edited with the 'visudo' command as root.
- 直接開かない
/etc/sudoers.d/
ディレクトリ以下にファイルを追加することも検討せよPlease consider adding local content in /etc/sudoers.d/ instead of
directly modifying this file.
visudo
コマンドで編集するEDITOR
環境変数のエディタで開く
手元のUbuntuの
/etc/sudoers
# # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
- CentOSコンテナのやつ
## Sudoers allows particular users to run various commands as ## the root user, without needing the root password. ## ## Examples are provided at the bottom of the file for collections ## of related commands, which can then be delegated out to particular ## users or groups. ## ## This file must be edited with the 'visudo' command. ## Host Aliases ## Groups of machines. You may prefer to use hostnames (perhaps using ## wildcards for entire domains) or IP addresses instead. # Host_Alias FILESERVERS = fs1, fs2 # Host_Alias MAILSERVERS = smtp, smtp2 ## User Aliases ## These aren't often necessary, as you can use regular groups ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname ## rather than USERALIAS # User_Alias ADMINS = jsmith, mikem ## Command Aliases ## These are groups of related commands... ## Networking # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool ## Installation and management of software # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum ## Services # Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig, /usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl reload, /usr/bin/systemctl restart, /usr/bin/systemctl status, /usr/bin/systemctl enable, /usr/bin/systemctl disable ## Updating the locate database # Cmnd_Alias LOCATE = /usr/bin/updatedb ## Storage # Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount ## Delegating permissions # Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp ## Processes # Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall ## Drivers # Cmnd_Alias DRIVERS = /sbin/modprobe # Defaults specification # # Refuse to run if unable to disable echo on the tty. # Defaults !visiblepw # # Preserving HOME has security implications since many programs # use it when searching for configuration files. Note that HOME # is already set when the the env_reset option is enabled, so # this option is only effective for configurations where either # env_reset is disabled or HOME is present in the env_keep list. # Defaults always_set_home Defaults match_group_by_gid # Prior to version 1.8.15, groups listed in sudoers that were not # found in the system group database were passed to the group # plugin, if any. Starting with 1.8.15, only groups of the form # %:group are resolved via the group plugin by default. # We enable always_query_group_plugin to restore old behavior. # Disable this option for new behavior. Defaults always_query_group_plugin Defaults env_reset Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS" Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE" Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES" Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE" Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY" # # Adding HOME to env_keep may enable a user to run unrestricted # commands via sudo. # # Defaults env_keep += "HOME" Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin ## Next comes the main part: which users can run what software on ## which machines (the sudoers file can be shared between multiple ## systems). ## Syntax: ## ## user MACHINE=COMMANDS ## ## The COMMANDS section may have other options added to it. ## ## Allow root to run any commands anywhere root ALL=(ALL) ALL ## Allows members of the 'sys' group to run networking, software, ## service management apps and more. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL ## Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL ## Allows members of the users group to mount and unmount the ## cdrom as root # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom ## Allows members of the users group to shutdown this system # %users localhost=/sbin/shutdown -h now ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) #includedir /etc/sudoers.d
- 書式
<ユーザ名> <ホスト名>=(<実行ユーザ名>) [NOPASSWD:]<コマンド>
- オプション
ユーザ名
- コマンドの実行を許可するユーザ名
- 先頭に
%
つきで、グループ名 ALL
ホスト名
- 実行を許可するホスト名
- IPアドレス
ALL
実行ユーザ名
- コマンド実行時のユーザ名
- 省略時
root
- 省略時
ALL
- コマンド実行時のユーザ名
コマンド
- 実行を許可するコマンドのパス
/sbin/shutdown
だけ許可する、とか
ALL
- 実行を許可するコマンドのパス
NOPASSWD:
- 指定するとパスワードを問われない
sudo
を許可するためのグループがある
sudo
の利用
- 引数でコマンド指定
- 許可コマンド調べる
sudo -l
既定値のエントリと照合中 (ユーザー名 wand) (ホスト名 wand-ThinkPad-X240s): env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin ユーザー wand は wand-ThinkPad-X240s 上で コマンドを実行できます (ALL : ALL) ALL
- 変更先ユーザでシェル起動
-i
- ログイン時の処理行う
su -
みたいな気持ち
-s
- ログイン時の処理行わない
su
みたいな気持ち
-u
- 変更先ユーザ指定
wand@wand-ThinkPad-X240s:~$ sudo -u hoge -s
hoge@wand-ThinkPad-X240s:~$
システムリソースの制限
ulimit
コマンド- ユーザが利用できるリソースを制限する
- さもないと1人のユーザが全てを使い切り、システムが停止する可能性がある
- 故意
- 不具合
ulimit -a
core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 30961 max locked memory (kbytes, -l) 16384 max memory size (kbytes, -m) unlimited open files (-n) 1048576 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
- オプションなし
ulimit
unlimited