权限-ACL

Linux 下用户对文件的操作权限有 r-读, w-写, x-可执行三种,而对linux 下的文件而言,用户身份分为:所有者, 所属组, 其它人, 且文件的所有者,所属组都只能是一个,所以在对文件分配用户的使用权限时,只能对这三种身份进行分配rwx 权限。但是Linux是多用户的系统,仅仅靠这个分配还是不够,要专门给某些用户分配特别的权限,就要涉及到ACL。

1、查看一个文件有没有被设置过ACL,可以ll -d

-rwxr–r–+ 1 root root 17 5月 12 16:27 f1
-rw-r–r–. 1 root root 0 5月 5 17:45 file

很显然f1可以看见有一个+的符号,说明有被设置过ACL,设置过ACL会自动出来一个mask,有mask就会出现+号,让我们知道设置过ACL,如果去掉mask,就看不见了,但是mask只能在里面的

[h1@localhost ~]$ sudo setfacl -x m:: /tmp/f1
[sudo] h1 的密码:
[h1@localhost ~]$ ll /tmp/
总用量 644
-rw-r–r–. 1 root root 15031 5月 12 20:01 anaconda.log
-rwxr–r–. 1 root root 17 5月 12 16:27 f1

就不会有mask

除了这个方法,用getfacl /文件也可以看有没有被设置过ACL

[h1@localhost ~]$ getfacl /tmp/f1
getfacl: Removing leading ‘/’ from absolute path names
# file: tmp/f1
# owner: root
# group: root
user::rwx
group::r–
mask::r–
other::r–

[h1@localhost ~]$ getfacl /tmp/file
getfacl: Removing leading ‘/’ from absolute path names
# file: tmp/file
# owner: root
# group: root
user::rw-
group::r–
other::r–

2、default是用于继承某目录下新建的acl列表

继承的是default里面的内容,而不是文件本身的ACL

[root@localhost p1]# getfacl p1
# file: p1
# owner: h1
# group: h1
user::rw-
user:h1:rwx
group::rwx
mask::rwx
other::r-x
default:user::rwx
default:user:h1:rwx
default:group::rwx
default:mask::rwx
default:other::r-x

[root@localhost p1]# mkdir ./p1/b
[root@localhost p1]# getfacl ./p1/b
# file: p1/b
# owner: root
# group: root
user::rwx
user:h1:rwx
group::rwx
mask::rwx
other::r-x
default:user::rwx
default:user:h1:rwx
default:group::rwx
default:mask::rwx
default:other::r-x

3、-b  恢复默认设置

[root@localhost p1]# getfacl p1
# file: p1
# owner: h1
# group: h1
user::rw-
user:h1:rwx
group::rwx
mask::rwx
other::r-x
default:user::rwx
default:user:h1:rwx
default:group::rwx
default:mask::rwx
default:other::r-x

[root@localhost p1]# setfacl -b p1

[root@localhost p1]# getfacl ./p1
# file: p1
# owner: h1
# group: h1
user::rw-
group::rwx
other::r-x

4、-x移除指定用户ACL

[root@localhost p1]# setfacl -m u:h1:rwx p1
[root@localhost p1]# getfacl ./p1
# file: p1
# owner: h1
# group: h1
user::rw-
user:h1:rwx
group::rwx
mask::rwx
other::r-x

[root@localhost p1]# setfacl -x u:h1:rwx p1
setfacl: Option -x: 无效的参数 near character 6
[root@localhost p1]# setfacl -x u:h1 p1
[root@localhost p1]# getfacl ./p1
# file: p1
# owner: h1
# group: h1
user::rw-
group::rwx
mask::rwx
other::r-x

但是要写好u:user,后面不加权限

猜你喜欢

转载自blog.csdn.net/qq_41201816/article/details/80767361