LPIC Level 1 対策: 第10章 - ユーザ管理

| |

newgrp

newgrp(1) はプライマリグループを、所属しているグループの中から切り替え ます。
この時、新しくシェルを起動するため exit を使って直前の状態にもどります。

$ id
uid=501(student) gid=501(student) 所属グループ=27(mysql),48(apache),499(store),
501(student) context=user_u:system_r:unconfined_t:s0
$ touch data1
$ ls -l data1
-rw-rw-r-- 1 student student 0 12月  8 23:19 data1

$ newgrp apache
$ id
uid=501(student) gid=48(apache) 所属グループ=27(mysql),48(apache),499(store),
501(student) context=user_u:system_r:unconfined_t:s0
$ touch data2
$ ls -l data2
-rw-r--r-- 1 student apache 0 12月  8 23:19 data2
$ exit
exit
$ id
uid=501(student) gid=501(student) 所属グループ=27(mysql),48(apache),499(store),
501(student) context=user_u:system_r:unconfined_t:s0

chage

chage(1) は、パスワードの有効期限を制御します。

# chage -l student
Last password change					: Dec 01, 2014
Password expires					: Dec 03, 2014
Password inactive					: never
Account expires 					: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 2
Number of days of warning before password expires	: 7

# ssh student@localhost
student@localhost's password:
You are required to change your password immediately (password aged)
Last login: Mon Dec  8 23:39:12 2014 from localhost.localdomain
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user student.
Changing password for student
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
Connection to localhost closed.

sudo

sudo は一般ユーザに特権コマンドの実行を許可する。/etc/sudoers に利用可能コマンドを追加する。
# visudo
/etc/suders 例
# includedir /etc/sudoers.d
student ALL=(ALL)	/sbin/shutdown -r +10
コマンドに引数やオプションまで指定すると、それらも合致しない限り実行されない。
$ sudo shutdown -h 23:00
[sudo] password for student:
ユーザー student は'/sbin/shutdown -h 23:00' を root として h006.s160.la.net 上で実行することは許可されていません。すみません。
$ sudo shutdown -r +10
[sudo] password for student:
Shutdown scheduled for 日 2016-12-11 12:28:42 JST, use 'shutdown -c' to cancel.
Broadcast message from root@h006.s160.la.net (Sun 2016-12-11 12:18:42 JST):
The system is going down for reboot at Sun 2016-12-11 12:28:42 JST!