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

参考链接

  1. 如何把普通用户添加到sudoers file
  2. /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 --help
visudo - safely edit the sudoers fileusage: visudo [-chqsV] [-f sudoers]Options:-c, --check              check-only mode-f, --file=sudoers       specify sudoers file location-h, --help               display 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” 这行,在下面添加一行:

username     ALL=(ALL)       ALL

如果想要在使用“sudo -s”时跳过输入密码,则可以添加一行:

username    ALL=(ALL)       NOPASSWD:ALL

username是具体的用户名称。

然后Esc退出编辑,最后 :X保存并退出。

【完】


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部