Sudoedit

sudoers - 如何同時使用 NOPASSWD 和 sudoedit?

  • October 25, 2013

在 /etc/sudoers 中同時使用 NOPASSWD 和 sudoedit 的語法是什麼?我試過這個:

john ALL=(ALL) NOPASSWD: sudoedit /path/to/file

但我仍然被提示輸入密碼。

sudoers 文件

你應該能夠做到這些。

  1. 比如這樣:
john ALL=(ALL) NOPASSWD: sudoedit
  1. 或這個:
john ALL=(ALL) NOPASSWD: sudoedit /path/to/file
  1. 最後你也可以這樣做:
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/filewhich 將呼叫具有提升權限的編輯器。

摘自 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.

您可以通過將上面提到的環境變數之一設置為要使用的編輯器的名稱來覆蓋編輯器,例如vimgedit

引用自:https://unix.stackexchange.com/questions/97578