1. 程式人生 > >解決linux下sudo更改檔案許可權報錯xxxis not in the sudoers file. This incident will be reported.

解決linux下sudo更改檔案許可權報錯xxxis not in the sudoers file. This incident will be reported.

Linux中普通使用者用sudo執行命令時報”xxx is not in the sudoers file.This incident will be reported”錯誤,解決方法就是在/etc/sudoers檔案裡給該使用者新增許可權。如下:

1.切換到root使用者下
  方法為直接在命令列輸入:su,然後輸入密碼(即你的登入密碼,且密碼預設不可見)。

2./etc/sudoers檔案預設是隻讀的,對root來說也是,因此需先新增sudoers檔案的寫許可權,命令是:
即執行操作:chmod u+w /etc/sudoers

3.編輯sudoers檔案
即執行:vi /etc/sudoers
找到這行 root ALL=(ALL) ALL,在他下面新增xxx ALL=(ALL) ALL (這裡的xxx是你的使用者名稱)

ps:這裡說下你可以sudoers新增下面四行中任意一條
youuser ALL=(ALL) ALL
%youuser ALL=(ALL) ALL
youuser ALL=(ALL) NOPASSWD: ALL
%youuser ALL=(ALL) NOPASSWD: ALL

第一行:允許使用者youuser執行sudo命令(需要輸入密碼).
第二行:允許使用者組youuser裡面的使用者執行sudo命令(需要輸入密碼).
第三行:允許使用者youuser執行sudo命令,並且在執行的時候不輸入密碼.
第四行:允許使用者組youuser裡面的使用者執行sudo命令,並且在執行的時候不輸入密碼.

4.撤銷sudoers檔案寫許可權,命令:
chmod u-w /etc/sudoers