报错
xxx is not in the sudoers file. This incident will be reported.
解决方式
切换到root用户下操作
# 1、修改/etc/sudoers文件为可修改,默认是只读的
ls -lh /etc/sudoers
-r--r----- 1 root root 4.3K Dec 1 01:45 /etc/sudoers
chmod u+w /etc/sudoers
ls -lh /etc/sudoers
-rw-r----- 1 root root 4.3K Dec 1 01:45 /etc/sudoers
# 2、添加用户配置
vi /etc/sudoers
root ALL=(ALL) ALL
username ALL=(ALL) NOPASSWD: ALL
# 3、恢复文件为只读状态
chmod u-w /etc/sudoers
ls -lh /etc/sudoers
-r--r----- 1 root root 4.3K Mar 22 15:24 /etc/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命令,并且在执行的时候不输入密码.
参考文章
解决linux下sudo更改文件权限报错xxxis not in the sudoers file. This incident will be reported.
https://blog.csdn.net/sinat_36118270/article/details/62899093