Samba 服务器存在问题,挂载点归 root 所有,而不是 smbd.conf 中指定的“强制用户”所有

Samba 服务器存在问题,挂载点归 root 所有,而不是 smbd.conf 中指定的“强制用户”所有

我在名为 teslausb 的 ubuntu 服务器 (v22.04) 上创建了一个名为 samba 共享,并在 smbd.conf 中指定了以下几行:

   [teslausb]
   comment = John's home share on Ubuntu
   path = /mnt/sdb1/teslausb
   browseable = yes
   writeable = yes
   valid users = john
   write list = john
   force user = john
   force group = john

john:john 是 /mnt/sdb1/teslausb 的所有者,我已将权限设置为 chmod -R 755:

john@docker:/mnt/sdb1/teslausb$ ls -al
total 1600
drwxrwxr-x 2 john john    4096 Oct 18 14:17 .
drwxrwxr-x 4 john john    4096 Oct 18 02:38 ..
-rwxrwxr-x 1 john john    4096 Oct 18 03:20 ._10.11.12.11-netconsole.log
-rwxrwxr-x 1 john john 1608971 Oct 10 14:55 10.11.12.11-netconsole.log
-rwxrwxr-x 1 john john    2653 Dec 13  2016 avrflash
-rwxrwxr-x 1 john john    4096 Oct 18 02:39 ._.DS_Store
-rwxrwxr-x 1 john john    6148 Oct 18 02:58 .DS_Store

当我通过 Windows 连接到共享时,写入共享没有任何问题,但是,当我使用 在 Ubuntu 机器上安装共享时sudo mount -t cifs -o user=john //docker/teslausb /mnt/teslausb/,我无法写入已安装的共享。我收到“权限被拒绝”错误消息。

由于某些奇怪的原因,尽管在 smbd.conf 中指定了“强制用户”,但挂载的共享也显示 root 是该共享中文件的所有者。

john@vm-ubuntu:/mnt/teslausb$ ls -al
total 1596
drwxr-xr-x 2 root root       0 Oct 18 14:17 .
drwxr-xr-x 6 root root    4096 Oct 18 12:25 ..
-rwxr-xr-x 1 root root    4096 Oct 18 03:20 ._10.11.12.11-netconsole.log
-rwxr-xr-x 1 root root 1608971 Oct 10 14:55 10.11.12.11-netconsole.log
-rwxr-xr-x 1 root root    2653 Dec 13  2016 avrflash
-rwxr-xr-x 1 root root    4096 Oct 18 02:39 ._.DS_Store
-rwxr-xr-x 1 root root    6148 Oct 18 02:58 .DS_Store

如果我挂载共享并在挂载命令中指定 uid 和 gui,sudo mount -t cifs -o user=john,uid=john,gid=john //docker/teslausb /mnt/teslausb/我就可以写入 samba 共享,但我试图避免在挂载命令中指定这一点,并认为通过使用“强制用户”应该可以实现相同的结果。

我也尝试过使用 chmod -R 777 来访问 samba 共享,但这没有帮助。

我有点困惑这应该如何工作。为什么这个共享是以 root 用户身份挂载的?有人能帮我吗?提前感谢任何帮助,我真的很感激。

答案1

mount.cifs 是一个虚拟文件系统,它在 SMB 共享的客户端计算机上创建一个“视图”,并赋予该客户端独有的权限。对于服务器,您是 john(用户 = john),拥有 john 在该服务器上拥有的所有权限。但是,客户端有自己的规则。

默认情况下,它将以 755 模式与owner=group=root一起挂载。但由于它是一个“视图”,因此您可以控制该“视图”在客户端上的体现方式。

因此 uid=john / gid=john 将取代 root 成为您的所有者 / 组。

您还可以更改模式。例如:

dir_mode=0777,file_mode=0666

这会将安装上的权限从 755 更改为 777,从而允许客户端上的每个人都可以写入共享。请记住,对于服务器来说,所有这些用户都是“john”。

相关内容