如何让一个任意的组挂载一个文件系统?

据我所知,从mount手册页,默认情况下只允许root挂载一个文件系统。 具有userusers选项的文件系统可以由任何用户装载。 ownergroup选项仅允许所有者和设备文件组的成员分别挂载/卸载文件系统。

有没有办法只允许任意组挂载/卸载文件系统?

@ Iain的答案适用于任何Unix系统。 但是,在linux中,您还可以专门允许一个组挂载设备。

  • 使设备拥有你想要允许它挂载的组
  • 在/ etc / fstab中,使用选项“group”而不是“user”

这在mount(8)的手册页(而不是用于fstab的,容易混淆)中描述:

  FILESYSTEM INDEPENDENT MOUNT OPTIONS [...] group Allow an ordinary (ie, non-root) user to mount the filesys- tem if one of his groups matches the group of the device. This option implies the options nosuid and nodev (unless over- ridden by subsequent options, as in the option line group,dev,suid). 

以下是一个使用卷“vg_firefly-testmount”的例子。 我是“jenny”组的用户“jenny”。

 [jenny@firefly ~]$ ls -ld /dev/mapper/vg_firefly-testmount lrwxrwxrwx 1 root root 7 Nov 26 10:43 /dev/mapper/vg_firefly-testmount -> ../dm-4 [jenny@firefly ~]$ ls -l /dev/dm-4 brw-rw---- 1 root jenny 253, 4 Nov 26 11:35 /dev/dm-4 [jenny@firefly ~]$ grep testmount /etc/fstab /dev/mapper/vg_firefly-testmount /testmount ext4 group,noauto,rw 1 2 [jenny@firefly ~]$ mount /testmount [jenny@firefly ~]$ mount | grep testmount /dev/mapper/vg_firefly-testmount on /testmount type ext4 (rw,nosuid,nodev,user=jenny) 

通常的做法是使用sudo

  • 创build一个组并添加特权用户。
  • 创build一个执行mount / unmount操作的脚本
  • 确保脚本是可执行的,但只能由root写入。
  • 编辑sudoers以允许组执行脚本
  • 利润