73 ## The COMMANDS section may have other options added to it.
74 ##
75 ## Allow root to run any commands anywhere
76 root ALL=(ALL) ALL
77 test ALL=(root) /usr/sbin/useradd //新增加用户行 ……后面省略
说明: 第一个字段:root为能使用sudo命令的用户; 第二个字段:第一个ALL为允许使用sudo的主机,第二个括号里的ALL为使用sudo后以什么身份(目的用户身份)来执行命令; 第三个字:ALL为以sudo命令允许执行的命令; 上列解释: test ALL=(root) /usr/sbin/useradd 表示允许test用户从任何主机登录,以root的身份执行/usr/sbin/useradd命令。
用户执行命令效果:
[root@server ~]# su - redhat [redhat@server ~]$ sudo /usr/sbin/useradd test //命令需要输入完整的路径 口令: //这里输入用户redhat自己的密码 [redhat@server ~]$ cat /etc/passwd |tail -5 xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin gdm:x:42:42::/var/gdm:/sbin/nologin sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin redhat:x:500:500::/home/redhat:/bin/bash test:x:501:501::/home/test:/bin/bash //新增加的用户
2、sudo配置深入:
2.1多个用户的设置(非同一群组用户): u 对于不同需求的用户:可以按照上面的方法依次增加多行,每行对应一个用户。 u 对于相同需求的多个用户 User_Alias UUU=user1,user2…… 定义用户别名;
[root@localhost ~]# visudo ……前面省略 16 ## User Aliases 17 ## These aren't often necessary, as you can use regular groups 18 ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname 19 ## rather than USERALIAS 20 # User_Alias ADMINS = jsmith, mikem //这个就是一个实例行,按照这个写自己的 21 User_Alisa sudouser=user1,user2,user3,user4 //第一一个别名suduouser
……后面省略
69 ## Syntax:
70 ##
71 ## user MACHINE=COMMANDS
72 ##
73 ## The COMMANDS section may have other options added to it.