ACL权限

本文详细介绍了ACL(访问控制列表)在文件和文件夹上的使用,包括通过getfacl、chmod、setfacl等命令进行权限设置,以及如何为特定用户和用户组赋予或取消特殊访问权限的操作过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

访问控制列表

 

# 文件

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--

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值