Linux类系统为用户添加sudo权限
一.命令
1.修改sudoers这个文件中的用户,vi /etc/sudoers
,找到如下这一行,
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
并在其后添加
[username] ALL=(ALL) ALL
:这表示执行普通用户可以使用sudo去拥有一些root权限,并且在执行命令时,不用输入密码了【建议使用这个命令】
或者[username] ALL=(ALL) NOPASSWD:ALL
:这表示执行普通用户可以使用sudo去拥有一些root权限,并且在执行命令时,需要先输入一次密码。
二.验证
1.使用命令:[username] ALL=(ALL) ALL
[laowang@localhost ~]$ ls /root#没有使用sudo关键字---->导致拒绝访问
ls: cannot open directory /root: Permission denied
[laowang@localhost ~]$ sudo ls /root #使用sudo命令 -->可以正常访问
anaconda-ks.cfg test.txt
2.使用命令:[username] ALL=(ALL) NOPASSWD:ALL
[laowang@localhost ~]$ ls /root
ls: cannot open directory /root: Permission denied
[laowang@localhost ~]$ sudo ls /root #需要输入一次命令
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 laowang:
anaconda-ks.cfg