1. 程式人生 > >Linux中新建用戶用不了sudo命令問題:rootr is not in the sudoers file.This incident will be reported解決

Linux中新建用戶用不了sudo命令問題:rootr is not in the sudoers file.This incident will be reported解決

c-c++ 進入 去掉註釋 去掉 sudo命令 wheel gpasswd sdn 通用

參考:https://blog.csdn.net/lichangzai/article/details/39501025

如果執行sudo命令的用戶沒有執行sudo的權限,執行sudo命令時會報下面的錯

[rootr@localhost ]# sudo yum install gcc-c++
rootr is not in the sudoers file.This incident will be reported

設置用戶執行sudo命令權限,建議這些操作都在secureCRT內進行要不然當走到進入sudoers那一步時,會出現問題
方法如下:
1、進入超級用戶模式。也就是輸入"su -",系統會讓你輸入超級用戶密碼,輸入密碼後就進入了超級用戶模式。



2、添加文件的寫權限。也就是輸入命令"chmod u+w /etc/sudoers"。

技術分享圖片


3、編輯/etc/sudoers文件。也就是輸入命令"vim /etc/sudoers",輸入"i"進入編輯模式,
找到這一行:"root ALL=(ALL) ALL"在起下面添加"xxx ALL=(ALL) ALL"(這裏的xxx是你的用戶名),比如我這裏是rootr所以我的語句是:rootr ALL=(ALL) ALL

技術分享圖片

如果要讓執行時不需要輸入密碼,再找到下面這一句
# %wheel ALL=(ALL) NOPASSWD: ALL

並去掉註釋#:
%wheel ALL=(ALL) NOPASSWD: ALL



然後保存(就是先摁一下Esc鍵,然後輸入":wq")退出。

4、將你的用戶(普通用戶)調整至“ wheel ”用戶組裏面。
gpasswd -a YourUserName wheel

這樣,就可以每次執行 sudo 命令時不再輸入密碼了

5、撤銷文件的寫權限。也就是輸入命令"chmod u-w /etc/sudoers"。

[oracle@dev ]$ su root
[root@dev ]# chmod u+w /etc/sudoers
[root@dev ]# vim /etc/sudoers
[root@dev ]# chmod u-w /etc/sudoers
[root@dev ]# gpasswd -a rootr wheel

[root@dev ]# su rootr

截圖:

技術分享圖片

之後就可以執行sudo啦,截圖留念:

技術分享圖片

Linux中新建用戶用不了sudo命令問題:rootr is not in the sudoers file.This incident will be reported解決