linux ACL权限规划:getfacl,setfacl使用

简介:

                     linux ACL权限规划:getfacl,setfacl使用

                          ACL的使用

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

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

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

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

   

 setfacl 参数

  -m:设置后续acl参数 

  -x:删除后续acl参数  

  -b:删除全部的acl参数

  -k:删除默认的acl参数

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

  -d:设置默认acl

例:创建一文件test,将其权限修改为777,并查看其默认ACL权限配置

    [root@Self-study ~]# touch /test

    [root@Self-study ~]# chmod 777 /test

    [root@Self-study ~]# getfacl /test             //获得文件的ACL权限

    getfacl: Removing leading '/' from absolute path names

    # file: test                                //文件名

    # owner: root                             //文件所属者

    # group: root                             //文件所属组

    user::rwx                                //文件所属者权限

    group::rwx                               //同组用户权限

    other::rwx                               //其它者权限

[root@Self-study ~]# 

可以看到其它者的权限也是可读可写可执行,可以自行测试,现在我们修改其ACL策略,使用用户code只有读取的权限

 [root@Self-study ~]# setfacl -m u:code:r /test

[root@Self-study ~]# ll /test

-rwxrwxrwx+ 1 root root 1 Apr 11 07:25 /test            //可以看到权限的最后多了一个+

[root@Self-study ~]# 

现在再次查看一下此文件的ACL属性

[root@Self-study ~]# getfacl /test

getfacl: Removing leading '/' from absolute path names

# file: test

# owner: root

# group: root

user::rwx

user:code:r--                           //可以看到code单独的权限为r--

group::rwx

mask::rwx

other::rwx

 [root@Self-study ~]# 

注:code的权限并不是只根据ACL配置来决定的,它是由code用户基本权限与配置的ACL权限的“与”运算决定的,即other:rwx 与 code:r--  = code:r--

现在使用code用户,测试是否可写

 在写文件时,会出现-- INSERT -- W10: Warning: Changing a readonly file提示。

除了对单个用户进行设置外,还可以对用户组、有效权限(mask)进行设置如对用户组设置:    g:[用户组]:[rwx] 

注:有效权限(mask) 即用户或组所设置的权限必须要存在于mask的权限设置范围内才会生效

 如上面的/test文件,已经有了可读权限,如果我们把它的有效权限修改为只有写权限,则设置的acl权限不在有效权限之内,则用户code就不可能再查看/test文件中的内容了

 [root@Self-study ~]# setfacl -m m:w /test              //设置有效权限为只写

可以查看/test acl属性

[root@Self-study ~]# getfacl /test

getfacl: Removing leading '/' from absolute path names

# file: test

# owner: root

# group: root

user::rwx

user:code:r-- #effective:---

group::rwx #effective:-w-

mask::-w-                       //可以看到有效权限已经修改成功

other::rwx

[root@Self-study ~]# 

使用code用户查看文件内容,首先使用root用户写入一些内容,会使测试更加直观

[root@Self-study ~]# echo "this is a test getfacl " >/test

[code@Self-study ~]$ vim /test 

 "/test" [Permission Denied]                     //可以在最下面看到不允许访问的提示,并且看不到任何内容

取消acl权限

[root@Self-study ~]# setfacl -x u:code /test             //取消/test对用户code的权限

    [root@Self-study ~]# setfacl -x m /test                 //恢复有效权限

    [root@Self-study ~]# getfacl /test               

    getfacl: Removing leading '/' from absolute path names

    # file: test

    # owner: root

    # group: root

    user::rwx

    group::rwx

    other::rwx

    [root@Self-study ~]# ll /test

    -rwxrwxrwx 1 root root 24 Apr 11 08:01 /test              //已经可以正常使用

    [root@Self-study ~]# 

    至于另外的一些参数,自己尝试使用!!










本文转自 guodong810 51CTO博客,原文链接:http://blog.51cto.com/guodong810/1176427,如需转载请自行联系原作者
目录
相关文章
|
17天前
|
安全 Linux 数据安全/隐私保护
Linux权限详解
Linux权限详解
|
27天前
|
Linux 数据安全/隐私保护 Windows
Linux入门指南:linux权限究竟是什么?和文件有什么关系?
Linux入门指南:linux权限究竟是什么?和文件有什么关系?
30 0
|
29天前
|
算法 Linux C++
【Linux系统编程】解析获取和设置文件信息与权限的Linux系统调用
【Linux系统编程】解析获取和设置文件信息与权限的Linux系统调用
29 0
|
1天前
|
安全 Linux Shell
【linux基础(四)】对Linux权限的理解
【linux基础(四)】对Linux权限的理解
|
1天前
|
Linux 网络安全 数据安全/隐私保护
Linux 如何关闭防火墙(开启管理员权限)
Linux 如何关闭防火墙(开启管理员权限)
2 0
|
2天前
|
Linux 数据安全/隐私保护 Windows
Linux的学习之路:4、权限
Linux的学习之路:4、权限
13 0
|
28天前
|
Ubuntu 关系型数据库 MySQL
linux创建用户创建组删除用户以及组分配权限
linux创建用户创建组删除用户以及组分配权限
10 0
|
30天前
|
Shell Linux 开发工具
shell的介绍以及Linux权限的讲解
shell的介绍以及Linux权限的讲解
31 2
|
1月前
|
Shell Linux C语言
【Shell 命令集合 网络通讯 】Linux 设置终端机的写入权限 mesg 命令 使用指南
【Shell 命令集合 网络通讯 】Linux 设置终端机的写入权限 mesg 命令 使用指南
23 0
|
1月前
|
安全 Shell Linux
【Shell 命令集合 文件管理】Linux 设置文件创建时的默认权限掩码 umask命令使用教程
【Shell 命令集合 文件管理】Linux 设置文件创建时的默认权限掩码 umask命令使用教程
26 0