在挂载cifs共享时始终使用777权限



当我从Synology NAS挂载SMB共享文件夹时遇到了一个小问题。我想挂载一个共享文件夹,权限为:git:root 700

但是挂载的文件夹总是将权限设置为777(即使在没有错误的chmod 700之后)

在我的/etc/fstab中,我使用了这行:

#uid=999 ---> git user
//server/folder /mnt/artifacts cifs username=windowsUser,password=xxxxx,gid=0,uid=999,file_mode=0700,dir_mode=0700,iocharset=utf8 0 0

你知道为什么我的权限不能设置为700吗?我犯了一个错误?什么蠢事?

提前感谢您的帮助;)

如果远程机器用户ID和本地机器用户ID不匹配,权限将默认为777。山。Cifs不支持umask,所以可以使用"noperm"选项。这样,即使本地和远程机器上的用户权限不匹配,用户仍然可以对文件夹进行读写操作,相当于umask=000。

//address/location /mount/location cifs username=username,password=password,noperm,vers=2.0 0 0

一个好的开始是查看CIFS的手册:

$ man mount.cifs
[...]
   file_mode=arg
       If the server does not support the CIFS Unix extensions this overrides the default file mode.
   dir_mode=arg
       If the server does not support the CIFS Unix extensions this overrides the default mode for directories.
[...]
   nounix
       Disable the CIFS Unix Extensions for this mount. 
[...]

因此,由于file_mode(和dir_mode)似乎只有在服务器不支持CIFS Unix扩展时才能工作,我将首先禁用它们(通过nounix选项)

添加nounix效果很好。对于信息,我在/etc/fstab中的行是:

//server/share /mnt/folder cifs credentials=/home/yannick/.smbcredentials,iocharset=utf8,sec=ntlm,vers=1.0,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,nounix 0 0

使用1000作为我的用户id和组id。

.smbcredentials里面,我有这个:

username=<distant login>
password=<distant password>

我尝试挂载一个只有root权限的CIFS共享。其他用户甚至不能列出任何文件。

因此我使用了下面的fstab条目:

//192.168.0.100/DRV   /mnt/DRV   cifs   user=user,pass=pass,uid=0,gid=0,nounix,file_mode=0007,dir_mode=0007   0   0

我还尝试了noperm参数。

详细地说,我创建了一个具有以下权限的文件夹:

drwxrwx--- 2 root root 4096 Mai 14 09:09 DRV

挂载网络共享后,文件夹有:

d------rwx 2 root root 4096 Mai 14 04:50 W

你的问题很常见。您正在使用不正确的标签来更改挂载文件夹的文件权限。

您需要添加'umask=',而不是'file_mode=700''dir_mode=700',因为它使用的是系统挂载选项而不是CIFS的选项。

你可以使用:

//address/location /mount/location cifs credentials=/location,uid=id,gid=id,umask=700 0 0

这将以设置的文件权限挂载文件共享。

为了安全起见,我建议使用凭证文件,其中包含用户名和密码,并且必须设置为只读。

最新更新