xxx is not in the sudoers file.This incident will be reported.的解決方法

centos 執行sudo 命令是出現的以下錯誤

xxx is not in the sudoers file.This incident will be reported

原因是沒有爲普通用戶賦予sudo權限


1.切換到root用戶下

2.添加sudo文件的寫權限,命令是:
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

這樣普通用戶就可以使用sudo了.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章