文章目录
root 用户下给普通用户添加 sudo 权限
useradd syhj
passwd syhj
chmod u+w /etc/sudoers
vi /etc/sudoers
......
100 root ALL=(ALL) ALL
101 syhj ALL=(ALL) ALL
......
chmod u-w /etc/sudoers
普通用户下第一次 sudo 需要输入该普通用户的密码
[root@master ~]#useradd syhj
[root@master ~]#echo 120604 | passwd --stdin syhj
Changing password for user syhj.
passwd: all authentication tokens updated successfully.
[root@master ~]#su - syhj
[syhj@master ~]$cat /root/test.yaml
cat: /root/test.yaml: Permission denied
[syhj@master ~]$sudo cat /root/test.yaml
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 syhj:
syhj is not in the sudoers file. This incident will be reported.
[syhj@master ~]$exit
logout
You have new mail in /var/spool/mail/root
[root@master ~]#chmod u+w /etc/sudoers
[root@master ~]#vi /etc/sudoers
[root@master ~]#chmod u-w /etc/sudoers
[root@master ~]#su - syhj
Last login: Tue Aug 9 17:34:16 CST 2022 on pts/2
[syhj@master ~]$cat /root/test.yaml
cat: /root/test.yaml: Permission denied
[syhj@master ~]$sudo cat /root/test.yaml
[sudo] password for syhj:
apiVersion: v1
kind: Namespace
metadata:
name: test
finalizers:
- kubernetes
[syhj@master ~]$exit
logout