sudo命令的好处就是可以普通用户不需要知道root用户的密码,也可以进行root用户还能进行的操作,只需要输入普通用户自己的密码就行
它可以实现比su命令更细粒度的操作
如果我们有很多服务器,每个服务器root用户密码不一样,需要把用户密码逐个记下来,但是用了sudo,我们只需要记住普通用户的密码就行,不需要知道root用户的密码
使用sudo还有一个好处就是,如果系统有很多运维人员,每个人都通过自己账号的sudo来操作系统,万一出错了,sudo可以提供审计,如果每个人都是使用root来操作系统,万一操作错误,就不好追查是哪个用户操作的了。
新建一个测试用户,并给用户设置密码
[root@10-13-53-194 ~]# useradd test
[root@10-13-53-194 ~]# passwd test
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@10-13-53-194 ~]#
未对test用户做任何sudo命令相关的设置,切换到新建的test用户
[root@10-13-53-194 ~]# su - test
[test@10-13-53-194 ~]$ sudo -l
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 test:
Sorry, user test may not run sudo on 10-13-53-194.
[test@10-13-53-194 ~]$ sudo ls /root
[sudo] password for test:
test is not in the sudoers file. This incident will be reported.
[test@10-13-53-194 ~]$
[te