linux 权限acl怎么用,linux ACL权限的使用

一、ACL使用介绍

ACL即Access Control List 主要的目的是提供传统的owner,group,others的read,write,execute权限之外的具体权限设置,ACL可以针对单一用户、单一文件或目录来进行r,w,x的权限控制,对于需要特殊权限的使用状况有一定帮助。如,某一个文件,不让单一的某个用户访问。

二、getfacl、setfacl两个命令的介绍和常用选项

1、ACL使用两个命令来对其进行控制

getfacl:取得某个文件/目录的ACL设置项目

setfacl:设置某个文件/目录的ACL设置项目

2、setfacl 参数

-m:设置后续acl参数

-x:删除后续acl参数

-b:删除全部的acl参数

-k:删除默认的acl参数

-R:递归设置acl,包括子目录

-d:设置默认acl

三、使用举例

在linux系统中我们在用普通用户(cangls)编辑文本文件时,可能要编辑别的普通用户(bols)的文件,通常情况下我们会想到下面两个解决方法:1、用root用户把普通用户(cangls)添加到要编辑文件的所属组(bols)中,然后可以更加属组的写权限就可以编辑文件。2、若我们不想用root用户更改权限则可以让被编辑文件所属主(bols)在文本的other权限中添加写权限。上面的两个解决方法虽然都能可以解决问题但是root权限在生产服务器上一般不会随便登录的,而第二种虽然能解决问题但由于其他用户也有写权限,若被有心人利用就得不偿失了,今天就向大家介绍个能同时避免上面两个问题的解决方法即使用setfacl命令。

1、使用环境列举[bols@hpf-linux test]$ whoami

bols

[bols@hpf-linux test]$ touch bols.txt

[bols@hpf-linux test]$ ls -l bols.txt

-rw-rw-r-- 1 bols bols 0 7月   9 08:00 bols.txt[cangls@hpf-linux test]$ whoami

cangls

[cangls@hpf-linux test]$ echo "cangls" > bols.txt

-bash: bols.txt: 权限不够

2、使用setfacl命令赋予的属主的权限进行更改文件[bols@hpf-linux test]$ getfacl bols.txt

# file: bols.txt

# owner: bols

# group: bols

user::rw-

group::rw-

other::r--

[bols@hpf-linux test]$ setfacl -m u:cangls:rw- /tmp/test/bols.txt

Try `getfacl --help' for more information.

[bols@hpf-linux test]$ getfacl bols.txt

# file: bols.txt

# owner: bols

# group: bols

user::rw-

user:cangls:rw-

group::rw-

mask::rw-

other::r--

[bols@hpf-linux test]$ ls -l bols.txt

-rw-rw-r--+ 1 bols bols 12 7月   9 08:33 bols.txt[cangls@hpf-linux test]$ echo "cangls" > bols.txt

[cangls@hpf-linux test]$ cat bols.txt

cangls[bols@hpf-linux test]$ setfacl -x u:cangls bols.txt    //取消权限

[bols@hpf-linux test]$ getfacl bols.txt

# file: bols.txt

# owner: bols

# group: bols

user::rw-

group::rw-

mask::rw-

other::r--

[cangls@hpf-linux test]$ echo "bols" > bols.txt

-bash: bols.txt: 权限不够

3、使用setfacl命令赋予的属组的权限进行更改文件[bols@hpf-linux test]$ setfacl -m g:cangls:rwx bols.txt

[bols@hpf-linux test]$ getfacl bols.txt

# file: bols.txt

# owner: bols

# group: bols

user::rw-

group::rw-

group:cangls:rwx

mask::rwx

other::r--

[bols@hpf-linux test]$ ls -l bols.txt

-rw-rwxr--+ 1 bols bols 12 7月   9 08:33 bols.txt[cangls@hpf-linux test]$ echo "bols" >> bols.txt

[cangls@hpf-linux test]$ cat bols.txt

cangls

bols[bols@hpf-linux test]$ setfacl -x g:cangls bols.txt

[bols@hpf-linux test]$ getfacl bols.txt

# file: bols.txt

# owner: bols

# group: bols

user::rw-

group::rw-

mask::rw-

other::r--

[cangls@hpf-linux test]$ echo "bols" > bols.txt

-bash: bols.txt: 权限不够

4、-R递归目录用法举例[bols@hpf-linux tmp]$ setfacl -R -m  u:cangls:rwx /tmp/test/

[bols@hpf-linux tmp]$ getfacl /tmp/test/bols.txt

getfacl: Removing leading '/' from absolute path names

# file: tmp/test/bols.txt

# owner: bols

# group: bols

user::rw-

user:cangls:rwx

group::rw-

mask::rwx

other::r--

[bols@hpf-linux tmp]$ getfacl /tmp/test/

getfacl: Removing leading '/' from absolute path names

# file: tmp/test/

# owner: bols

# group: bols

user::rwx

user:cangls:rwx

group::rwx

mask::rwx

other::r-x

[bols@hpf-linux tmp]$ ls -ld test/

drwxrwxr-x+ 2 bols bols 4096 7月   9 08:00 test/[cangls@hpf-linux test]$ echo "cangls" >> bols.txt

[cangls@hpf-linux test]$ cat bols.txt

cangls

bols

cangls

通过上面三个简单的小例子可以看出通过setfacl命令可以很好的解决文件权限的问题,希望通过此例子技巧的学习能给你的学习工作带来便利。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值