创建用户user1、user2、user3。在/data/下创建目录test

 [root@Centos8 ~]# useradd user1;useradd user2;useradd user3

[root@Centos8 ~]# mkdir /data/test

[root@Centos8 ~]# ls /data
test

 

1、目录/data/test属主、属组为user1

 

[root@Centos8 ~]# chown user1:user1 /data/test
[root@Centos8 ~]# ll -d /data/test/
drwxr-xr-x. 2 user1 user1 6 Nov 30 16:41 /data/test/

 

2、在目录属主、属组不变的情况下,user2对文件有读写权限

 

[root@Centos8 ~]# setfacl -m u:user2:rw /data/test
[root@Centos8 ~]# getfacl /data/test

 

 

3、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除a1.sh,a2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh

 

[root@Centos8 ~]# su - user1

[user1@Centos8 ~]$ cd /data/test

[user1@Centos8 test]$ touch a{1..4}.sh
[user1@Centos8 test]$ ls
a1.sh a2.sh a3.sh a4.sh

[user1@Centos8 test]$ exit

logout

[root@Centos8 ~]# chattr +i /data/test/a{1..2}.sh

[root@Centos8 ~]# lsattr /data/test
----i--------------- /data/test/a1.sh
----i--------------- /data/test/a2.sh
-------------------- /data/test/a3.sh
-------------------- /data/test/a4.sh

[root@Centos8 ~]# chmod o+t /data/test/a{3..4}.sh

[root@Centos8 ~]# ll -d /data/test/*
-rw-rw-r--. 1 user1 user1 0 Nov 30 16:48 /data/test/a1.sh
-rw-rw-r--. 1 user1 user1 0 Nov 30 16:48 /data/test/a2.sh
-rw-rw-r-T. 1 user1 user1 0 Nov 30 16:48 /data/test/a3.sh
-rw-rw-r-T. 1 user1 user1 0 Nov 30 16:48 /data/test/a4.sh

 

4、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件

 

[root@Centos8 ~]# gpasswd -a user3 user1
Adding user user3 to group user1

[root@Centos8 ~]# id user3
uid=1005(user3) gid=1005(user3) groups=1005(user3),1003(user1)

[root@Centos8 ~]# chmod -R o=--- /data/test

 

 

5、清理/data/test目录及其下所有文件的acl权限

[root@Centos8 ~]# setfacl -R -b /data/test
[root@Centos8 ~]# getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
group::r-x
other::r--

 

[root@Centos8 ~]# getfacl /data/test/*
getfacl: Removing leading '/' from absolute path names
# file: data/test/a1.sh
# owner: user1
# group: user1
user::rw-
group::rw-
other::r--

 

# file: data/test/a2.sh
# owner: user1
# group: user1
user::rw-
group::rw-
other::r--

 

# file: data/test/a3.sh
# owner: user1
# group: user1
# flags: --t
user::rw-
group::rw-
other::r--

 

# file: data/test/a4.sh
# owner: user1
# group: user1
# flags: --t
user::rw-
group::rw-
other::r--

posted @ 2022-03-09 15:28  海月如希  阅读(1096)  评论(0编辑  收藏  举报