#1、创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt
[root@localhost ~]# groupadd g1
[root@localhost ~]# useradd redhat
[root@localhost ~]# touch redhat.txt
[root@localhost ~]# chown redhat /root/redhat.txt
[root@localhost ~]# ll /root
总用量 4
-rw-------. 1 root root 990 5月 1 18:31 anaconda-ks.cfg
-rw-r--r--. 1 redhat root 0 5月 1 18:35 redhat.txt
[root@localhost ~]# chown :g1 /root/redhat.txt
[root@localhost ~]# ll /root
总用量 4
-rw-------. 1 root root 990 5月 1 18:31 anaconda-ks.cfg
-rw-r--r--. 1 redhat g1 0 5月 1 18:35 redhat.txt
#2、新建/sc目录,所属组为group组,root用户和group组用户可在该目录下创建文件,其他人无任何权限
[root@localhost ~]# mkdir /sc
[root@localhost ~]# groupadd group
[root@localhost ~]# chown :group /sc
[root@localhost ~]# ll -d /sc
drwxr-xr-x. 2 root group 6 5月 1 18:38 /sc
[root@localhost ~]# chmod 770 /sc
[root@localhost ~]# ll -d /sc
drwxrwx---. 2 root group 6 5月 1 18:38 /sc
#3、新建/cw目录为财务部存储目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于mygroup组中
[root@localhost ~]# mkdir /cw
[root@localhost ~]# groupadd mygroup
[root@localhost ~]# chown :mygroup /cw
[root@localhost ~]# ll -d /cw
drwxr-xr-x. 2 root mygroup 6 5月 1 18:49 /cw
[root@localhost ~]# chmod 770 /cw
[root@localhost ~]# chmod g+s /cw
[root@localhost ~]# ll -d /cw
drwxrws---. 2 root mygroup 6 5月 1 18:49 /cw
[root@localhost ~]# useradd yanzhen
[root@localhost ~]# gpasswd mygroup -a yanzhen
正在将用户“yanzhen”加入到“mygroup”组中
[root@localhost cw]# su - yanzhen
[yanzhen@localhost ~]$ touch /cw/file
[yanzhen@localhost ~]$ ll /cw
总用量 0
-rw-r--r--. 1 yanzhen mygroup 0 5月 1 19:00 file
#4、设置helen用户对于/sc和/cw目录可读、可写、可执行
[root@localhost ~]# useradd helen
[root@localhost ~]# setfacl -m u:helen:rwx /sc
[root@localhost ~]# setfacl -m u:helen:rwx /cw
[root@localhost ~]# getfacl /sc /cw
getfacl: Removing leading '/' from absolute path names
# file: sc
# owner: root
# group: group
user::rwx
user:helen:rwx
group::rwx
mask::rwx
other::---
# file: cw
# owner: root
# group: mygroup
# flags: -s-
user::rwx
user:helen:rwx
group::rwx
mask::rwx
other::---
#5、设置/test目录为公共存储目录,对所有用户可以读、写、执行,但用户只能删除属于自己的文件。
[root@localhost ~]# mkdir /test
[root@localhost ~]# chmod 777 /test/
[root@localhost ~]# ll -d /test/
drwxrwxrwx. 2 root root 6 5月 1 19:07 /test/
[root@localhost ~]# chmod o+t /test/
[root@localhost ~]# ll -d /test/
drwxrwxrwt. 2 root root 6 5月 1 19:07 /test/
#6、在/test/dir里创建的新文件自动属于temp组
[root@localhost ~]# groupadd temp
[root@localhost ~]# mkdir -pv /test/dir
mkdir: 已创建目录 '/test/dir'
[root@localhost ~]# chown :temp /test/dir/
[root@localhost ~]# ll -d /test/dir/
drwxr-xr-x. 2 root temp 6 5月 1 19:12 /test/dir/
[root@localhost ~]# chmod g+s /test/dir/