系统管理指南:安全性服务

Procedure如何将 ACL 项添加到文件

  1. 使用 setfacl 命令设置文件的 ACL。


    % setfacl -s user::perms,group::perms,other:perms,mask:perms,acl-entry-list filename ...
    
    -s

    设置文件的 ACL。如果文件已具有 ACL,则会替换该 ACL。此选项要求至少有 user::group::other:: 项。

    user::perms

    指定文件属主权限。

    group::perms

    指定组属主权限。

    other:perms

    为文件属主或组成员之外的用户指定权限。

    mask:perms

    指定 ACL 掩码的权限。掩码表示允许用户(属主除外)和组拥有的最大权限。

    acl-entry-list

    指定文件或目录中要为特定用户和组设置的一个或多个 ACL 项的列表。也可以设置目录的缺省 ACL 项。表 6–7表 6–8 显示了有效的 ACL 项。

    filename ...

    指定要对其设置 ACL 的一个或多个文件或目录。多个 filename 由空格分隔。


    注意 – 注意 –

    如果该文件已存在 ACL,则 -s 选项将使用新的 ACL 替换整个 ACL。


    有关更多信息,请参见 setfacl(1) 手册页。

  2. 检验是否已对文件设置了 ACL 项。


    % getfacl filename
    

    有关更多信息,请参见如何检查文件是否具有 ACL


示例 6–7 设置文件的 ACL

在以下示例中,会在 ch1.sgm 文件中将文件属主权限设置为读写、将文件组权限设置为只读,并将其他用户权限设置为无。此外,还在文件中为用户 anusha 指定读写权限。将 ACL 掩码权限设置为读写,这意味着任何用户或组都没有执行权限。


% setfacl -s user::rw-,group::r--,other:---,mask:rw-,user:anusha:rw- ch1.sgm

% ls -l

total 124

-rw-r-----+  1 stacey  techpubs   34816 Nov 11 14:16 ch1.sgm

-rw-r--r--   1 stacey  techpubs   20167 Nov 11 14:16 ch2.sgm

-rw-r--r--   1 stacey  techpubs    8192 Nov 11 14:16 notes

% getfacl ch1.sgm

# file: ch1.sgm

# owner: stacey

# group: techpubs

user::rw-

user:anusha:rw-    #effective:rw-

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

mask:rw-

other:---

在以下示例中,会将文件属主权限设置为读写和执行,将文件组权限设置为只读,并将其他用户权限设置为无。此外,还会在 ch2.sgm 文件中将 ACL 掩码权限设置为读。最后,将为用户 anusha 指定读写权限。但是,由于 ACL 掩码的原因,anusha 的权限为只读。


% setfacl -s u::7,g::4,o:0,m:4,u:anusha:7 ch2.sgm

% getfacl ch2.sgm

# file: ch2.sgm

# owner: stacey

# group: techpubs

user::rwx

user:anusha:rwx         #effective:r--

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

mask:r--

other:---