![如何允许任意组挂载文件系统?](https://linux22.com/image/621628/%E5%A6%82%E4%BD%95%E5%85%81%E8%AE%B8%E4%BB%BB%E6%84%8F%E7%BB%84%E6%8C%82%E8%BD%BD%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%EF%BC%9F.png)
据我从mount
手册页中了解到,默认情况下,只有 root 才允许挂载文件系统。任何用户都可以挂载带有user
或选项的文件系统。和选项分别仅允许设备文件的所有者和组成员挂载/卸载文件系统。users
owner
group
有没有办法只允许任意组挂载/卸载文件系统?
答案1
@Iain 的答案适用于任何 unix。然而,在 linux 中,您还可以专门允许某个组安装设备。
- 让该设备归你希望允许挂载它的组所有
- 在 /etc/fstab 中,使用选项“group”而不是“user”
这是在手册页中描述的mount(8)
(而不是 fstab 的手册页,令人困惑):
FILESYSTEM INDEPENDENT MOUNT OPTIONS
[...]
group Allow an ordinary (i.e., 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)