CentOS版本:8.2

假设我要用的账号为:test

默认安装完毕后,使用非root账号执行带sudo的命令,想获取管理员权限执行此命令,发现无法执行,提示:



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


解决方法:在sudoers文件中加入要执行此命令的用户

1,切换成root账号



su


随后输入root账号,切换为root身份!

2,修改sudoers文件



gedit  /etc/sudoers


打开这个文件后,查找:root ALL=(ALL) ALL 这行,随后在这行下面加入:你的用户名 ALL=(ALL) ALL ,随后保存退出就可以了!!

编辑后这个地方应该是:



root ALL=(ALL) ALL

test ALL=(ALL) ALL


在shell里面输入:



su test


随后输入test的密码就可以了,切换为test身份了,随后输入测试命令:



sudo echo hello


这个时候就应该可以了!!