sudoers条目

有没有办法让一个sudoers条目,只允许执行一个特定的命令,没有任何额外的参数? 我似乎无法find描述命令匹配如何与sudoers一起工作的资源。

假设我想为/path/to/executable arg授予sudo。

是否有如下条目:

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

严格允许sudo访问一个完全匹配的命令? 也就是说,它不授予用户sudo权限/path/to/executable arg arg2

我在Cmnd_List定义附近发现了一个man sudoers

  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)上的处理方式有些不一致。 所以你应该testing你自己的环境。

一个有点丑陋的解决方法:创build一个单独的可执行脚本,只用所需的参数运行指定的命令,然后将sudo访问权授予该脚本而不是原始命令。

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