Samba-使用自己的权限创建子目录共享


9

我有一个Samba共享,其中包含许多文件夹,如下所示:

share
  - folderA
  - folderB
  - folderC
  - folderD

大约有20位用户正在访问这些共享。每个用户都可以访问某些目录,例如Ben可以访问folderA和folderC,但不能访问folderB和folderD。珍妮可以访问folderB和folderC,依此类推。

我不希望用户挂载他们需要的每个文件夹。我希望他们安装包含所有子文件夹的文件夹“ share”。然后通过设置linux权限来限制访问。

我为每个子目录创建了一个组,并将用户添加到了这些组。访问控制非常适合现有文件。但是,只要用户在子目录中创建文件,其他在该目录中具有读/写访问权限的其他用户都将拒绝该文件。为了解决这个问题,我试用了samba遮罩,但无法使其正常工作。

我的Samba conf看起来像这样:

guest ok = no

[global]
workgroup = WORKGROUP
security  = user
encrypt passwords = yes

[Share]
path        = /var/samba
valid users = @everybody
read only   = no
writeable   = yes

[folderA]
path        = /var/samba/folderA
valid users = @users_folderA
read only   = no
writeable   = yes

create mask          = 770
directory mask       = 770
force directory mode = 770

force group = users_folderA

[folderB]
path        = /var/samba/folderB
valid users = @users_folderB
read only   = no
writeable   = yes

create mask          = 770
directory mask       = 770
force directory mode = 770

force group = users_folderB

[folderC]
path        = /var/samba/folderC
valid users = @users_folderC
read only   = no
writeable   = yes

create mask          = 770
directory mask       = 770
force directory mode = 770

force group = users_folderC

[folderD]
path        = /var/samba/folderD
valid users = @users_folderD
read only   = no
writeable   = yes

create mask          = 770
directory mask       = 770
force directory mode = 770

force group = users_folderD

因此,显然每个用户都在组中,因此他们可以与子目录挂载共享。每个子目录的访问都可以正常工作。但是每当Ben在folderC中创建文件时,该文件都会获得文件权限-rwxr--r--,但应为-rwxrwx--

我认为单个文件夹的共享根本不起作用,因为我尝试将writeable设置为no并仅将read设置为yes进行测试。重新启动smbd和nmbd并重新安装网络共享(在Windows 10中)。用户能够创建文件并修改自己的文件。

它在带有树莓派的树莓派上运行。带有文件的硬盘驱动器格式化为ext4并通过fstab挂载。


要强制对文件进行所需的访问权限,请使用配置部分中的force create mode = 770语句folderC
Oleg Bolden

谢谢,这实际上并不能解决问题,但是我注意到我的真实smb.conf的路径中有空格:[folderA] path = / var / samba /一些带有空格的文件夹。我通过用“(” /“ / var / samba / some文件夹带空格”)封闭路径来解决此问题。[folderA]段中的设置仅在用户直接安装[folderA]时才使用。 。当用户安装[分享]和导航到folderA [分享]的设置用于folderA使用如何可以旁路folderA的[分享]设置,而不直接安装folderA但从[分享]访问它。?
soner

Answers:


5

尝试以下配置(对于共享部分):

[Share]
path        = /var/samba
valid users = @everybody
force group = +everybody
writeable   = yes
create mask = 0660
force create mode = 0110
directory mask = 0770

[folderA]
path        = /var/samba/folderA
valid users = @users_folderA
force group = +users_folderA
browseable = no

[folderB]
path        = /var/samba/folderB
valid users = @users_folderB
force group = +users_folderB
browseable = no

[folderC]
path        = /var/samba/folderC
valid users = @users_folderC
force group = +users_folderC
browseable = no

[folderD]
path        = /var/samba/folderD
valid users = @users_folderD
force group = +users_folderD
browseable = no

不要忘记检查配置并重新启动samba:

# testparm
# service smbd restart
# service nmbd restart

设置权限:

chown root:everybody /var/samba
chmod 770 /var/samba
chown root:users_folderA /var/samba/folderA
chmod 2770 /var/samba/folderA
chown root:users_folderB /var/samba/folderB
chmod 2770 /var/samba/folderB
chown root:users_folderC /var/samba/folderC
chmod 2770 /var/samba/folderC
chown root:users_folderD /var/samba/folderD
chmod 2770 /var/samba/folderD

这种方式不允许直接访问内部文件夹。此外,它们根本不可见,只能通过父文件夹进行访问。


谢谢,这工作。现在,我们又遇到一个问题,Excel 2016无法将大于13 KB的文件保存到Samba。但这是另一个话题。非常感谢您的帮助!
2016年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.