在 /etc/sudoers 中同时使用 NOPASSWD 和 sudoedit 的语法是什么?我试过这个:
john ALL=(ALL) NOPASSWD: sudoedit /path/to/file
但系统仍提示我输入密码。
答案1
sudoers 文件
您应该能够执行其中任何一项操作。
比如这样:
john ALL=(ALL) NOPASSWD: sudoedit
或这个:
john ALL=(ALL) NOPASSWD: sudoedit /path/to/file
最后你也可以这样做:
Cmnd_Alias SOMECMD = sudoedit /path/to/file john ALL=(ALL) NOPASSWD: SOMECMD
一旦你有了这些定义之一,你就可以像这样调用它:
sudoedit /path/to/file
细节
您不需要使用sudo
如下命令前缀来调用它:
sudo sudoedit /pat/to/file
它会自动处理sudo
。它相当于sudo -e /pat/to/file
将调用具有提升权限的编辑器。
摘自 sudo/sudoedit 手册页
-e The -e (edit) option indicates that, instead of running a command,
the user wishes to edit one or more files. In lieu of a command, the
string "sudoedit" is used when consulting the sudoers file. If the
user is authorized by sudoers the following steps are taken:
1. Temporary copies are made of the files to be edited with the
owner set to the invoking user.
2. The editor specified by the SUDO_EDITOR, VISUAL or EDITOR
environment variables is run to edit the temporary files.
If none of SUDO_EDITOR, VISUAL or EDITOR are set, the first
program listed in the editor sudoers variable is used.
3. If they have been modified, the temporary files are copied
back to their original location and the temporary versions
are removed.
vim
您可以通过使用要使用的编辑器的名称(例如或)设置上述环境变量之一来覆盖编辑器gedit
。