设为首页 收藏本站
查看: 313|回复: 0

[经验分享] linux ACL权限的使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-10 08:29:22 | 显示全部楼层 |阅读模式
一、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、使用环境列举
1
2
3
4
5
[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



1
2
3
4
[cangls@hpf-linux test]$ whoami
cangls
[cangls@hpf-linux test]$ echo "cangls" > bols.txt
-bash: bols.txt: 权限不够




2、使用setfacl命令赋予的属主的权限进行更改文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[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



1
2
3
[cangls@hpf-linux test]$ echo "cangls" > bols.txt
[cangls@hpf-linux test]$ cat bols.txt
cangls



1
2
3
4
5
6
7
8
9
10
11
[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命令赋予的属组的权限进行更改文件

1
2
3
4
5
6
7
8
9
10
11
12
[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



1
2
3
4
[cangls@hpf-linux test]$ echo "bols" >> bols.txt
[cangls@hpf-linux test]$ cat bols.txt
cangls
bols



1
2
3
4
5
6
7
8
9
10
11
[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递归目录用法举例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[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/



1
2
3
4
5
[cangls@hpf-linux test]$ echo "cangls" >> bols.txt
[cangls@hpf-linux test]$ cat bols.txt
cangls
bols
cangls




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


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-84977-1-1.html 上篇帖子: 奔跑中的2015:Linux运维学习八大禁忌 下篇帖子: linux系统参数注释 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表