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 file

usage: 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保存并退出。

【完】

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值