有限的Linux管理员帐户仅提供VM磁盘驱动器扩展

有限的Linux管理员帐户仅提供VM磁盘驱动器扩展

问题标题总结了一切。我正在部署一个基于 Debian 9 的网络设备作为虚拟机,但想让用户能够在需要时添加额外的磁盘空间,但我不希望他们在命令行上拥有完整的系统访问权限。我如何创建一个仅限于执行 fdisk 类型活动的帐户?此外,我想限制他们的文件系统访问权限,以便他们无法浏览磁盘。

答案1

您应该只自动执行调整虚拟硬盘和文件系统大小的任务。

例如,cloud-init 可以设置为自动扩大分区(和文件系统)的虚拟机实例,并且已在 Amazon AWS 和 Google Cloud 等主要云提供商的 VM 实例上设置为这样做。您可以自己使用 cloud-init 来自动执行此任务。在这种情况下,最终用户将调整其虚拟机管理程序中的虚拟磁盘大小,然后重新启动实例,cloud-init 将自动执行所有必要的步骤。

文档中的示例:

#cloud-config
#
# growpart entry is a dict, if it is not present at all
# in config, then the default is used ({'mode': 'auto', 'devices': ['/']})
#
#  mode:
#    values:
#     * auto: use any option possible (any available)
#             if none are available, do not warn, but debug.
#     * growpart: use growpart to grow partitions
#             if growpart is not available, this is an error.
#     * off, false
#
# devices:
#   a list of things to resize.
#   items can be filesystem paths or devices (in /dev)
#   examples:
#     devices: [/, /dev/vdb1]
#
# ignore_growroot_disabled:
#   a boolean, default is false.
#   if the file /etc/growroot-disabled exists, then cloud-init will not grow
#   the root partition.  This is to allow a single file to disable both
#   cloud-initramfs-growroot and cloud-init's growroot support.
#
#   true indicates that /etc/growroot-disabled should be ignored
#
growpart:
  mode: auto
  devices: ['/']
  ignore_growroot_disabled: false

答案2

您可以使用 sudoers 文件(/etc/sudoers,但最好使用该工具进行编辑visudo)来允许一组用户使用 sudo(8) 来限制特定命令。您甚至可以添加允许的参数,以便用户无法在无关的磁盘上调用 fdisk。

文件中的条目可能看起来像这样:

%yourgroup ALL=(ALL) NOPASSWD: /sbin/fdisk /dev/sdb

man sudoers有更多关于命令语法和可能选项的信息。

相关内容