有限的 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有關於命令語法和可能的選項的更多資訊。

相關內容