zoukankan      html  css  js  c++  java
  • FACL 文件系统的权限设置 枯木

     

    FACL 文件系统的权限设置(file access contrl list) 文件访问控制列表

     

    针对Unix系统权限机制的不足,一个名为POSIX ACL的全新权限机制诞生了,目的就是为了给各Unix系统之间制定一个兼容的ACL标准,使得各操作系统之间使用统一的接口。ACL为现有权限机制的延伸,在现有机制的三个基本设定(ownergroupother)的基础上加入了对某指定使用者或群组的存取权限设定。

     

    Linux Kernel 2.6上已经正式支持POSIX ACL,常用的档案系统(如:ext2,ext3,xfs,jfs以及ReiserFS)都能使用ACL。当然,在编译kernel时需要启动ACL

     

    相关的kernel option:

     

    CONFIG_FS_POSIX_ACL

    CONFIG_EXT3_POSIX_ACL

    CONFIG_EXT2_POSIX_ACL

     

    rules:

     

    user:(uid/name):(perms)             指定某位使用者的权限

    group:(gid/name):(perms)            指定某一群组的权限

    other::(perms)                    指定其它使用者的权限

    mask::(perms)                       设定有效的权限屏蔽

     

    ACL可以对某个文件设置该文件具体的某些用户的权限,意思就是通过ACL可以对一个文件权限做扩展,可以不同的用户对某个文件有不同的权限。

    option:

     

    -m             新增或修改ACL中的规则

    -x             移出ACL中的规则

     

    getfacl <文件名> 获取文件的访问控制信息

    setfacl设置文件的acl  -m 修改文件的acl  -x 取消对文件的设置

    setfacl –m u:用户名:权限 文件名

    setfacl –m g:组名:权限 文件名

     

    要设定预设型ACL只需在每个规则前加上"default:"

    例如: setfacl -m default:user::rw /home/alex

              或简写为: setfacl -m d:u::rw /home/alex

     

    [root@haha ~]# getfacl hello_world  查看文件的acl权限

    # file: hello_world

    # owner: root

    # group: root

    user::rw-

    group::r--

    other::r--

     

    [root@haha ~]# setfacl -m student:rwx hello_world  让用户student拥有rwx权限

    [root@haha ~]# getfacl hello_world

    # file: hello_world

    # owner: root

    # group: root

    user::rw-

    user:student:rwx

    group::r--

    mask::rwx

    other::r--

     

    [root@haha ~]# setfacl -m g:student:rx hello_world 让组student拥有rwx权限

    [root@haha ~]# getfacl hello_world

    # file: hello_world

    # owner: root

    # group: root

    user::rw-

    user:student:rwx

    group::r--

    group:student:r-x

    mask::rwx

    other::r--

     

     

    [root@haha ~]# ll hello_world

    -rw-rwxr—+ 1 root root 0 07-21 13:48 hello_world

    [root@haha ~]# setfacl -x student hello_world       解除student用户对文件的acl权限

    [root@haha ~]# setfacl -x g:student hello_world  解除student组对文件的权限

    (撤消ACL操作: 对用户直接加用户名字就可以了 对组,在前面加g:组名)

    [root@haha ~]# getfacl hello_world

    # file: hello_world

    # owner: root

    # group: root

    user::rw-

    group::r--

    mask::r--

    other::r--

     

    [root@haha ~]# getfacl hello_world

    # file: hello_world

    # owner: root

    # group: root

    user::rw-

    user:student:rwx

    group::r--

    group:student:rwx

    mask::rwx

    other::r--

     

    [root@haha ~]# setfacl -b hello_world           删除所有扩展的acl规则

    [root@haha ~]# getfacl hello_world

    # file: hello_world

    # owner: root

    # group: root

    user::rw-

    group::r--

    other::r--

     

    [root@haha lianxi]# getfacl a

    # file: a

    # owner: root

    # group: root

    user::rw-

    user:wl:rwx

    group::r--

    group:wl:rwx

    mask::rwx

    other::r--

     

    收回所有用户和所有组的写的权限

    [root@haha lianxi]# setfacl -m m::r-x a

    [root@haha lianxi]# getfacl a

    # file: a

    # owner: root

    # group: root

    user::rw-

    user:wl:rwx                     #effective:r-x

    group::r--

    group:wl:rwx                    #effective:r-x

    mask::r-x

    other::r--

     

     

     

    让子目录下的文件和文件夹继承

    [root@haha lianxi]# setfacl -m d:u:wl:rwx,g:wl:rwx b 其中d表示defaults

    [root@haha lianxi]# getfacl b

    # file: b

    # owner: root

    # group: root

    user::rwx

    group::r-x

    group:wl:rwx

    mask::rwx

    other::r-x

    default:user::rwx

    default:user:wl:rwx

    default:group::r-x

    default:mask::rwx

    default:other::r-x

     

    [root@haha lianxi]# cd b/

    [root@haha b]# mkdir c;touch d

    [root@haha b]# ls

    c  d

    [root@haha b]# getfacl c

    # file: c

    # owner: root

    # group: root

    user::rwx

    user:wl:rwx

    group::r-x

    mask::rwx

    other::r-x

    default:user::rwx

    default:user:wl:rwx

    default:group::r-x

    default:mask::rwx

    default:other::r-x

    [root@haha b]# getfacl d 可能由于文件本身的默认权限666问题,文件没有继承x权限

    # file: d

    # owner: root

    # group: root

    user::rw-

    user:wl:rwx                     #effective:rw-

    group::r-x                      #effective:r--

    mask::rw-

    other::r--

    getfacl a |setfacl —set-file=- b

     

    这是个很有意思的命令,它可以让一个文件的权限直接复制改成那一个文件的权限

     

    [root@haha lianxi]# ll

    总计 4

    -rw-rwxr--+ 1 root root 0 07-21 20:34 a

    -rw-r--r--  1 root root 0 07-21 20:34 b

    [root@haha lianxi]# getfacl a

    # file: a

    # owner: root

    # group: root

    user::rw-

    user:wl:rwx

    group::r--

    group:wl:rwx

    mask::rwx

    other::r--

     

    [root@haha lianxi]# getfacl a |setfacl --set-file=- b

    [root@haha lianxi]# ll

    总计 8

    -rw-rwxr--+ 1 root root 0 07-21 20:34 a

    -rw-rwxr--+ 1 root root 0 07-21 20:34 b

    [root@haha lianxi]# getfacl b

    # file: b

    # owner: root

    # group: root

    user::rw-

    user:wl:rwx

    group::r--

    group:wl:rwx

    mask::rwx

    other::r--

    [root@haha lianxi]#

     两个的文件权限是一样的,哈哈,有点像克隆的感觉。

     

  • 相关阅读:
    koa 基础(十)原生node.js 在 koa 中获取表单提交的数据
    koa 基础(九) ejs 模板引擎的使用
    koa 基础(八)koa 中间件的执行顺序
    koa 基础(七)错误处理中间件
    [翻译] KVNProgress
    编写带有点击特效的UIButton
    用Easing函数实现碰撞效果
    EasingAnimation
    什么时候会执行viewDidLoad方法
    UIButton的两种block传值方式
  • 原文地址:https://www.cnblogs.com/kumulinux/p/2149228.html
Copyright © 2011-2022 走看看