sti*_*mby 15 linux permissions access-control-list umask
假设我的 umask 是 0077。
我有一个目录,foo我想对其应用特殊权限。我在其中创建的所有文件foo都应该是全局可读的,并且所有目录都应该是全局可读和可执行的。
目前,如果我创建一个文件,它将是 0600,目录将是 0700:
$ cd foo/
$ touch file
$ mkdir directory
$ ls -l
drwx------ 2 nfm nfm 4096 2012-01-12 16:16 directory
-rw------- 1 nfm nfm 0 2012-01-12 16:15 file
Run Code Online (Sandbox Code Playgroud)
我希望文件是 0644,目录是 0755,不管我的 umask:
drwxr-xr-x 2 nfm nfm 4096 2012-01-12 16:16 directory
-rw-r--r-- 1 nfm nfm 0 2012-01-12 16:15 file
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
use*_*641 19
是的,ACL 可以做到这一点。
确保您的文件系统使用acl. 要检查这一点,请键入mount。您应该看到acl列出的其他权限,例如
/dev/sda1 on / type ext4 (rw,errors=remount-ro,acl)
Run Code Online (Sandbox Code Playgroud)
如果它没有用 acl 挂载,打开/etc/fstab并添加acl到选项列表中:
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sda1 / ext3 noatime,errors=remount-ro,acl 0 1
Run Code Online (Sandbox Code Playgroud)
现在,使用新选项重新挂载正在运行的文件系统:
mount -v -o remount /
Run Code Online (Sandbox Code Playgroud)
安装 acl 实用程序。在 ubuntu/debian 上,这是:
sudo apt-get install acl
Run Code Online (Sandbox Code Playgroud)
你的新朋友是setfacl和getfacl。使用setfacl更改默认的ACL的目录:
setfacl -d -m o:r foo
Run Code Online (Sandbox Code Playgroud)
-d设置默认值,-m修改 acl,并o:r授予“其他”读取权限。在目录上设置默认值大致相当于在目录上设置setgid,但新创建的文件不是继承组,而是继承 acl。setgid 和 acl 一起可以很强大,因为您可以向一个组授予默认权限,并让新创建的文件属于该组,以获得有效的基于组的每个目录 umask。
检查您的工作:ls -l现在应该显示一个额外的“+”,表明除了标准文件权限之外还存在 acl。
% ls -la foo/
drwxr--r--+
Run Code Online (Sandbox Code Playgroud)
您可以使用 获取有关 acl 的详细信息getfacl。
% getfacl foo
# file: foo
# owner: you
# group: you
user::rwx
group::r--
other::r--
default:user::rwx
default:group::---
default:other::r--
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24270 次 |
| 最近记录: |