sudoers的缺省配置:
#############################################################
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
##########################################################
1. 让普通用户admin具有root的所有权限
执行visudo之后,可以看见缺省只有一条配置:
root ALL=(ALL) ALL
那么你就在下边再加一条配置:
admin ALL=(ALL) ALL
这样,普通用户admin就能够执行root权限的所有命令
以admin用户登录之后,执行:
sudo su -
然后输入admin用户自己的密码,就可以切换成root用户了
2. 让用户admin和apache拥有部分命令的root权限,并且不需要输入密码
admin ALL= NOPASSWD: /usr/local/www/scripts/
apache ALL= NOPASSWD: /usr/local/www/scripts/,/usr/local/bin/