13.7. 锁定重新分区
polkit
可让您为单个操作设置权限。对于 udisks2
,磁盘管理服务工具,配置位于 /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy
。此文件包含一组操作和默认值,它们可被系统管理员覆盖。
重要
请记住,存储在
/etc
中的 polkit
配置会覆盖 /usr/share/
中软件包所提供的配置。
过程 13.7. 要禁止用户更改磁盘设置
- 创建一个与
/usr/share/polkit-1/actions/org.freedesktop.udisks2.policy
中内容相同的文件。cp /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy /etc/share/polkit-1/actions/org.freedesktop.udisks2.policy
不要更改/usr/share/polkit-1/actions/org.freedesktop.udisks2.policy
文件,您的更改会被下一次软件包更新覆盖。 - 删除您不需要的操作,并将以下行添加到
/etc/polkit-1/actions/org.freedesktop.udisks2.policy
文件中:<action id="org_freedesktop_udisks2_modify-device"> <message>Authentication is required to modify the disks settings</message> <defaults> <allow_any>no</allow_any> <allow_inactive>no</allow_inactive> <allow_active>yes</allow_active> </defaults> </action>
如果只想确保只有 root 用户才可以执行操作,则需要把no
替换为auth_admin
。 - 保存更改。
当用户尝试更改磁盘设置时,会返回以下信息:
Authentication is required to modify the disks settings