参考链接
如何把普通用户添加到sudoers file/etc/sudoers文件解析测试环境
操作系统:CentOS
xxx is not in the sudoers file
[ljl@VM-0-8-centos python]$ sudo -s[sudo] password for ljl:ljl is not in the sudoers file. This incident will be reported.
如上所示,普通用户执行“sudo -s”切换到root用户时报错:xxx is not in the sudoers file. This incident will be reported.
根据错误提示,当前用户不在sudoers file,需要将当前用户添加到sudoers file。
sudoers file是什么文件?
Sudoers allows particular users to run various commands as the root user, without needing the root password.
sudoer使得普通用户能像root用户一样执行各种命令,而不必使用root密码。
sudoers file默认指的是 文件/etc/sudoers:
$ ls -lha /etc/sudoers-r--r----- 1 root root 4.3K Oct 19 14:41 /etc/sudoers
如何把普通用户添加到sudoers file?
为了安全起见,/etc/sudoers文件是只读的,必须使用命令visudo
来编辑它:
$ visudo --helpvisudo - safely edit the sudoers fileusage: visudo [-chqsV] [-f sudoers]Options:-c, --check check-only mode-f, --file=sudoers specify sudoers file location-h, --helpdisplay help message and exit-q, --quiet less verbose (quiet) syntax error messages-s, --strict strict syntax checking-V, --version display version information and exit
root用户执行visudo,找到 “root ALL=(ALL) ALL” 这行,在下面添加一行:
usernameALL=(ALL) ALL
如果想要在使用“sudo -s”时跳过输入密码,则可以添加一行:
username ALL=(ALL) NOPASSWD:ALL
username是具体的用户名称。
然后Esc
退出编辑,最后:X
保存并退出。
【完】