【问题标题】:Linux/Unix - Setting default file/folder permissions using ACL, executable permission not setting?Linux/Unix - 使用 ACL 设置默认文件/文件夹权限,未设置可执行权限?
【发布时间】:2013-09-09 21:57:48
【问题描述】:

当新文件或文件夹被创建/上传到我的 Linux(RackSpace Cloud、CentOS)服务器时,我正在尝试设置默认权限和组。

我想将目录“public”的所有子文件/文件夹设置为具有以下内容:

User - rwx
Group - 'ftp', rwx
Other - r-x

我已使用此脚本(递归)设置 ACL:

setfacl -R -m u::rwx,g:ftp:rwx,d:g:ftp:rwx,o::rx public/

使用 getfacl 返回 acl 会显示以下内容:

# file: public/
# owner: james
# group: ftp
# flags: -s-
user::rwx
group::rwx
group:ftp:rwx
mask::rwx
other::r-x
default:user::rwx
default:group::rwx
default:group:ftp:rwx
default:mask::rwx
default:other::r-x

但创建新文件会返回此权限(从 FTP 使用用户“james”上传新文件时也会发生同样的情况):

-rw-rw-r--+ 1 root  root      6 Sep  5 15:26 test.html

为什么没有设置'x'和默认组'ftp',而是正确设置了其他权限?

【问题讨论】:

    标签: linux unix default acl file-permissions


    【解决方案1】:

    它没有设置执行位,因为只有在应用程序明确请求时才会创建具有执行权限的文件。由于使 .html 文件可执行是没有意义的,因此创建它的任何程序都没有请求添加执行权限,因此它没有执行权限。因此,默认 ACL 的执行权限有效仅适用于目录,不适用于文件。

    至于为什么默认组不设置为ftp,这个就比较微妙了。默认 ACL 就是这样——一个 ACL。这不是默认的组所有权。因此,它不会出现在 ls 中,而是出现在 getfacl 中:

    # mkdir public
    # setfacl -R -m u::rwx,g:ftp:rwx,d:g:ftp:rwx,o::rx public/
    # getfacl public
    # file: public
    # owner: root
    # group: root
    user::rwx
    group::r-x
    group:ftp:rwx
    mask::rwx
    other::r-x
    default:user::rwx
    default:group::r-x
    default:group:ftp:rwx
    default:mask::rwx
    default:other::r-x
    
    # echo hello, world > public/test.html
    # ls -l public
    total 4
    -rw-rw-r--+ 1 root root 13 Aug 29 13:00 test.html
    # getfacl public/test.html 
    # file: public/test.html
    # owner: root
    # group: root
    user::rw-
    group::r-x                      #effective:r--
    group:ftp:rwx                   #effective:rw-
    mask::rw-
    other::r--
    

    请注意,ftp 可以正常访问该文件,而其他人则不能:

    # cd public
    # su nobody -s /bin/bash -C "touch test.html"
    touch: cannot touch `test.html': Permission denied
    # su ftp -s /bin/bash -C "touch test.html"
    #
    

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2023-03-21
      • 2014-09-28
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 2011-12-18
      • 2023-03-28
      相关资源
      最近更新 更多