CentOS - 加入sudo列表,解决非root账号无法执行带sudo命令问题!!

CentOS版本:8.2

假设我要用的账号为:test

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

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

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

1,切换成root账号

su 

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

2,修改sudoers文件

visudo

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

编辑后这个地方应该是:

root ALL=(ALL) ALL

test ALL=(ALL) ALL

在shell里面输入:

su test

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

sudo echo hello

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

参考:

https://blog.csdn.net/lell3538/article/details/52148832

https://blog.csdn.net/BXD1314/article/details/16102633