访问控制列表
# 文件
getfacl 菜根谭.txt
# file: 菜根谭.txt
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
chmod u-x,g-x,o-x 菜根谭.txt
ls -l 菜根谭.txt
-rw-r--r-- 1 root root 50084 Aug 26 13:31 菜根谭.txt
getfacl 菜根谭.txt
# file: 菜根谭.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--
groups bob 「 切换bob用户,无法修改此文件」
bob : rootthomas
groups bob1 「other组用户, 无法修改此文件」
bob1 : bob1
setfacl -m u:bob1:rw- 菜根谭.txt 「--modify 用户bob1的权限rw-,可以修改此文件 」
getfacl 菜根谭.txt
# file: 菜根谭.txt
# owner: root
# group: root
user::rw-
user:bob1:rw- 「other」
group::r--
mask::rw-
other::r— 「o权限不变」
setfacl -m u:bob1:-w- 菜根谭.txt
[bob1@centos-linux src]$ cat 菜根谭.txt 「无读权限」
cat: 菜根谭.txt: Permission denied
setfacl -m u:bob1:rw- 菜根谭.txt
setfacl -x u:bob1 菜根谭.txt 「 --remove 取消bob1用户的特殊访问权限」
getfacl 菜根谭.txt
# file: 菜根谭.txt
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--
setfacl -m g:bob1:rw- 菜根谭.txt 「 对bob1组赋ACL特殊访问权限」
getfacl 菜根谭.txt
# file: 菜根谭.txt
# owner: root
# group: root
user::rw-
group::r--
group:bob1:rw-
mask::rw-
other::r--
groups bob1 「 切换bob1用户,可以编辑此文件」
bob1 : bob1
groups bob 「group组成员,只读此文件」
bob : root thomas
setfacl -x g:bob1 菜根谭.txt 「 取消bob1组的特殊权限」
getfacl 菜根谭.txt
# file: 菜根谭.txt
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--
# 文件夹
mkdir rhce
ls -dl rhce/
drwxr-xr-x 2 root root 4096 Sep 29 15:54 rhce/
groups bob 「 切换bob用户」
bob : root thomas
touch rhce/1.txt 「bob1无写权限」
touch: cannot touch ‘rhce/1.txt’: Permission denied
setfacl -m u:bob:rwx rhce/ 「 对bob用户赋ACL权限」
getfacl rhce/
# file: rhce/
# owner: root
# group: root
user::rwx
user:bob:rwx
group::r-x
mask::rwx
other::r-x
touch rhce/1.txt 「 切换bob用户」
ls rhce/
1.txt
setfacl -m u:bob:rw- rhce/
getfacl rhce/
# file: rhce/
# owner: root
# group: root
user::rwx
user:bob:rw-
group::r-x
mask::rwx
other::r-x
ls rhce/ 「 切换bob用户,无x权限」
ls: cannot access rhce/1.txt: Permission denied
1.txt
cd rhce/
-bash: cd: rhce/: Permission denied
touch rhce/2.txt
touch: cannot touch ‘rhce/2.txt’: Permission denied
setfacl -x u:bob rhce/ 「 取消bob用户的ACL权限」
setfacl -m d:u:bob:rwx rhce/ 「 default & bob用户对任何用户在rhce下的文件都有rwx权限」
getfacl rhce/
# file: rhce/
# owner: root
# group: root
user::rwx
group::r-x
mask::r-x
other::r-x
default:user::rwx
default:user:bob:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
cd rhce/ 「 切换root,创建的任何文件,bob用户都有rwx权限」
touch xx
getfacl xx
# file: xx
# owner: root
# group: root
user::rw-
user:bob:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--
touch yy
getfacl yy
# file: yy
# owner: root
# group: root
user::rw-
user:bob:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--
setfacl -x d:u:bob rhce/ 「 取消bob的默认ACL权限」
getfacl rhce/
# file: rhce/
# owner: root
# group: root
user::rwx
group::r-x
mask::r-x
other::r-x
default:user::rwx
default:group::r-x
default:mask::r-x
default:other::r-x
getfacl yy 「 保留」
# file: yy
# owner: root
# group: root
user::rw-
user:bob:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--