配置 Samba 权限

配置 Samba 权限

我想知道是否可以使文件可创建,但不可写或可移动。这样每个文件都被创建为具有r--r--r--权限。
我当前的 smb.conf:

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no

#=== Share Definitions ===

[Anonymous]
path = /samba/anon
browsable =yes
writable = yes
guest ok = yes
read only = no
force user = nobody
create mask = 0444
force create mode = 0444
directory mask = 0444
force directory mode = 0444

我坚持将 /samba/anon 权限设置为drw-rw-rw-.如果我删除w,用户将无法再创建文件,因为它可以删除文件。这个困境能否得到解决?

答案1

您可以尝试以下操作(我现在无法验证它是否有效,但应该可以):

[Anonymous]
path = /samba/anon
browsable =yes
writable = yes
guest ok = yes
read only = no
force user = nobody
create mask = 0644
force create mode = 0644
directory mask = 3775
force directory mode = 3775
inherit owner = yes

然后设置共享主目录的权限(其中 sambaadm 是与任何人不同的某个 Linux 用户):

chown -R sambaadm:nogroup /samba/anon
find /samba/anon -type d | xargs chmod 3775
find /samba/anon -not -type d | xargs chmod 0644

这利用目录上的粘滞位来使文件只能由所有者删除。使用“继承所有者”,您强制用户始终为 sambaadm,因此无人用户无法删除。还写入仅允许 sambaadm 允许的文件,而无人用户则可以使用其 nogroup 组成员身份写入目录。

相关内容