据我从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)