我正在尝试在创建新文件或文件夹/上传到我的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",而是正确设置其他权限?
它没有设置执行位,因为只有在应用程序明确请求时才使用执行权限创建文件。 由于使.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"
#