Linux 赋予普通用户执行特定权限sudo

sudo: switch user do something 可以让 某个user(WHO)以特定用户的身份权限(HOW),在什么机器上(Where),执行什么命令(What)

配置文件: /etc/sudoers

为保障语法的正确性,不建议vim直接编辑该配置文件;

编辑该配置文件使用visudo,visudo可以检查语法的正确性,相当于vi+sudo

如: 

 tony localhost=(root) ALL  tony用户,可以在本地,以root身份运行所有命令

tony2 ALL=(root) /usr/sbin/useradd  tony2可以在所有机器上,以root用户运行useradd命令

届时执行的时候,需要sudo + command执行

测试如下:

[root@tonywang ~]# tail /etc/sudoers
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
tony1 localhost=(root) ALL
tony2 ALL=(root) /usr/sbin/useradd
[root@tonywang ~]# su tony2
bash: /home/tony2/.bashrc: Permission denied
bash-4.2$ useradd llj
bash: /usr/sbin/useradd: Permission denied
bash-4.2$ sudo useradd llj

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 tony2: 
bash-4.2$ 
bash-4.2$ exit
exit
[root@tonywang ~]# id llj
uid=5018(llj) gid=5

另外,作为运维人员,还可以以别名的方式定义,用户别名,命令别名等;

具体可以查看man手册

你可能感兴趣的:(Shell)