方法一、直接修改/etc/sudoers文件
1. /etc/sudoers内容格式
# 用户myuser允许运行任何命令操作
myuser ALL=(ALL) ALL
# 用户组mygroup允许运行任何命令操作
%mygroup ALL=(ALL) ALL
2. 修改文件
root@centos-system$ vim /etc/sudoers
添加
myuser ALL=(ALL) ALL
方法二、将用户追加到sudo用户组
root@centos-system$ sudo usermod -a -G sudo userName
在 centos上可能会出现
usermod: group 'sudo' does not exist
因为centos默认没有sudo组,可以将你的用户指向wheel用户组, wheel用户组同样有sudo权限
所以在centos上可以使用如下命令添加用户组
root@centos-system$
sudo usermod -a -G wheel userName
操作后注销重新登录
修改后必须重新登录才生效,否则会报错
sunny is not in the sudoers file. This incident will be reported.
本文介绍两种在CentOS系统中为用户配置sudo权限的方法:一是直接编辑/etc/sudoers文件来指定用户或用户组的权限;二是通过usermod命令将用户加入到具有sudo权限的组中,通常使用wheel组。
2万+

被折叠的 条评论
为什么被折叠?



