centos 系统并没有将普通用户默认添加到sudoers用户组,所以在centos(6,7,8)中普通用户是无法使用sudo的,可是为了系统安全,特别如果是你的服务器是正式的生产服务器最好还是区分好root用户和普通用户。
sudoers的配置文件是/etc/sudoers
。
1.切换到root用户
su root
2.修改/etc/sudoers
文件属性
chmod u+w /etc/sudoers
3.修改sudoers
文件
vi /etc/sudoers
在sudoers
文件中找到下面这一行
#### Allow root to run any commands anywhere
root ALL=(ALL) ALL
在root
那行下面添加如下内容
username ALL=(ALL) ALL
username
是要加入sudoers
用户本机普通用户
修改之后的文件如下
#### Allow root to run any commands anywhere
root ALL=(ALL) ALL
username ALL=(ALL) ALL
4.撤销sudoers
文件的写权限
chmod u-w /etc/sudoers
5.验证
切换到普通用户,使用sudo
测试
sudo yum update
这是写在很久以前的一篇文章了,写这个东西的时候我的Linux功底还很弱,其实有更好的修改sudoers的方法,那就是使用
visudo
命令。