1.7. Setting up a Samba file share that uses POSIX ACLs


As a Linux service, Samba supports shares with POSIX ACLs. They enable you to manage permissions locally on the Samba server using utilities, such as chmod. If the share is stored on a file system that supports extended attributes, you can define ACLs with multiple users and groups.

注意

If you need to use fine-granular Windows ACLs instead, see Setting up a share that uses Windows ACLs.

Parts of this section were adopted from the Setting up a Share Using POSIX ACLs documentation published in the Samba Wiki. License: CC BY 4.0. Authors and contributors: See the history tab on the Wiki page.

1.7.1. Adding a share that uses POSIX ACLs

You can create a share named example that provides the content of the /srv/samba/example/ directory and uses POSIX ACLs.

Prerequisites

Samba has been set up in one of the following modes:

Procedure

  1. Create the directory if it does not exist. For example:

    # mkdir -p /srv/samba/example/
  2. If you run SELinux in enforcing mode, set the samba_share_t context on the directory:

    # semanage fcontext -a -t samba_share_t "/srv/samba/example(/.*)?"
    # restorecon -Rv /srv/samba/example/
  3. Set file system ACLs on the directory. For details, see:

  4. Add the example share to the /etc/samba/smb.conf file. For example, to add the share write-enabled:

    [example]
    	path = /srv/samba/example/
    	read only = no
    注意

    Regardless of the file system ACLs; if you do not set read only = no, Samba shares the directory in read-only mode.

  5. Verify the /etc/samba/smb.conf file:

    # testparm
  6. Open the required ports and reload the firewall configuration using the firewall-cmd utility:

    # firewall-cmd --permanent --add-service=samba
    # firewall-cmd --reload
  7. Restart the smb service:

    # systemctl restart smb

The standard ACLs on Linux support setting permissions for one owner, one group, and for all other undefined users. You can use the chown, chgrp, and chmod utility to update the ACLs. For more information, refer to the chown(1) and chmod(1) man pages on your system. If you require precise control, then you use the more complex POSIX ACLs, see

Setting extended ACLs on a Samba share that uses POSIX ACLs.

The following procedure sets the owner of the /srv/samba/example/ directory to the root user, grants read and write permissions to the Domain Users group, and denies access to all other users.

Prerequisites

  • The Samba share on which you want to set the ACLs exists.

Procedure

  • Run the following command to initialize the process:

    # chown root:"Domain Users" /srv/samba/example/
    # chmod 2770 /srv/samba/example/
    注意

    Enabling the set-group-ID (SGID) bit on a directory automatically sets the default group for all new files and subdirectories to that of the directory group, instead of the usual behavior of setting it to the primary group of the user who created the new directory entry.

If the file system the shared directory is stored on supports extended ACLs, you can use them to set complex permissions. Extended ACLs can contain permissions for multiple users and groups.

Extended POSIX ACLs enable you to configure complex ACLs with multiple users and groups. However, you can only set the following permissions:

  • No access
  • Read access
  • Write access
  • Full control

If you require the fine-granular Windows permissions, such as Create folder / append data, configure the share to use Windows ACLs. See Setting up a share that uses Windows ACLs.

The following procedure shows how to enable extended ACLs on a share. Additionally, it contains an example about setting extended ACLs.

Prerequisites

  • The Samba share on which you want to set the ACLs exists.

Procedure

  1. Enable the following parameter in the share’s section in the /etc/samba/smb.conf file to enable ACL inheritance of extended ACLs:

    inherit acls = yes

    For details, see the parameter description in the smb.conf(5) man page.

  2. Restart the smb service:

    # systemctl restart smb
  3. Set the ACLs on the directory. For example:

例 1.2. Setting Extended ACLs

The following procedure sets read, write, and execute permissions for the Domain Admins group, read, and execute permissions for the Domain Users group, and deny access to everyone else on the /srv/samba/example/ directory:

  1. Disable auto-granting permissions to the primary group of user accounts:

    # setfacl -m group::--- /srv/samba/example/
    # setfacl -m default:group::--- /srv/samba/example/

    The primary group of the directory is additionally mapped to the dynamic CREATOR GROUP principal. When you use extended POSIX ACLs on a Samba share, this principal is automatically added and you cannot remove it.

  2. Set the permissions on the directory:

    1. Grant read, write, and execute permissions to the Domain Admins group:

      # setfacl -m group:"DOMAIN\Domain Admins":rwx /srv/samba/example/
    2. Grant read and execute permissions to the Domain Users group:

      # setfacl -m group:"DOMAIN\Domain Users":r-x /srv/samba/example/
    3. Set permissions for the other ACL entry to deny access to users that do not match the other ACL entries:

      # setfacl -R -m other::--- /srv/samba/example/

    These settings apply only to this directory. In Windows, these ACLs are mapped to the This folder only mode.

  3. To enable the permissions set in the previous step to be inherited by new file system objects created in this directory:

    # setfacl -m default:group:"DOMAIN\Domain Admins":rwx /srv/samba/example/
    # setfacl -m default:group:"DOMAIN\Domain Users":r-x /srv/samba/example/
    # setfacl -m default:other::--- /srv/samba/example/

    With these settings, the This folder only mode for the principals is now set to This folder, subfolders, and files.

Samba maps the permissions set in the procedure to the following Windows ACLs:

Expand
PrincipalAccessApplies to

Domain\Domain Admins

Full control

This folder, subfolders, and files

Domain\Domain Users

Read & execute

This folder, subfolders, and files

Everyone [a]

None

This folder, subfolders, and files

owner (Unix User\owner) [b]

Full control

This folder only

primary_group (Unix User\primary_group) [c]

None

This folder only

CREATOR OWNER [d] [e]

Full control

Subfolders and files only

CREATOR GROUP [e] [f]

None

Subfolders and files only

[a] Samba maps the permissions for this principal from the other ACL entry.
[b] Samba maps the owner of the directory to this entry.
[c] Samba maps the primary group of the directory to this entry.
[d] On new file system objects, the creator inherits automatically the permissions of this principal.
[e] Configuring or removing these principals from the ACLs not supported on shares that use POSIX ACLs.
[f] On new file system objects, the creator’s primary group inherits automatically the permissions of this principal.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部