sudoers 條目

sudoers 條目

有沒有辦法讓 sudoers 條目只允許執行特定指令,而不需要任何額外的參數?我似乎找不到描述命令匹配如何與 sudoers 一起工作的資源。

假設我想授予 sudo 權限/path/to/executable arg

是否有類似以下的條目:

user ALL=(ALL) /path/to/executable arg

嚴格允許 sudo 存取與該命令完全匹配的命令?也就是說,它不授予使用者 sudo 權限/path/to/executable arg arg2?

答案1

man sudoers我在 Cmnd_List 定義附近找到以下內容:

 A simple filename allows the user to run the command with any arguments
 he/she wishes.  However, you may also specify command line arguments
 (including wildcards).  Alternately, you can specify "" to indicate
 that the command may only be run without command line arguments.

這似乎意味著專門允許“arg”將不允許“arg arg2”。另一方面,我發現 sudoers 檔案在不同作業系統(例如 Linux 與 Solaris)上的處理方式有些不一致。所以你應該測試你自己的環境。

一種有點醜陋的解決方法:建立一個單獨的可執行腳本,僅使用所需的參數執行指定的命令,並授予 sudo 對該腳本而不是原始命令的存取權限。

 #!/bin/bash
 /path/to/executable arg

相關內容