rocky linux:添加sudoer用户(Rocky Linux 9.1)
一,查看sudo的版本:
[root@img ~]# sudo -V
Sudo version 1.9.5p2
Configure options: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu
…
如未安装,可以用yum命令安装
二,添加用户:
[root@img ~]# groupadd webop
[root@img ~]# useradd -g webop webop
[root@img ~]# ls /home/webop/
[root@img ~]# grep webop /etc/passwd
webop:x:1000:1000::/home/webop:/bin/bash
[root@img ~]# passwd webop
Changing password for user webop.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
三,使新添加用户可sudo
1,用新添加的用户sudo,会报错
[webop@img ~]$ sudo -i
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for webop:
webop is not in the sudoers file. This incident will be reported.
2,把webop添加到wheel组
[root@img ~]# groups webop
webop : webop
[root@img ~]#
[root@img ~]# usermod -aG wheel webop
[root@img ~]# groups webop
webop : webop wheel
再次sudo,成功了
[webop@img ~]$ sudo -i
[sudo] password for webop:
[root@img ~]#
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/06/rocky-linux-tian-jia-sudoer-yong-hu-rocky-linux-9-1/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
四,为什么把用户加入wheel组后可以sudo?
[root@img ~]# grep wheel /etc/sudoers
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
# %wheel ALL=(ALL) NOPASSWD: ALL
说明:可以看到 wheel用户组是被配置为运行所有命令的sudoer
五,查看linux的版本:
[root@blog ~]# cat /etc/redhat-release
Rocky Linux release 9.1 (Blue Onyx)