sudoers文件配置小记
程序员文章站
2022-05-10 09:48:32
...
需求
让普通用户ftpadmin可以创建、删除用户/组,但不授予其它权限
分析
ftpadmin用户可以以任何主机登录(不限制HOST),并且在任何路径下可以执行useradd,userdel,groupadd,groupdel,passwd这几个命令。
sudoers解读
修改sudoers时要用visudo,不要用vim
常见的命令组
## Command Aliases
## These are groups of related commands...
## Networking
# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool
## Installation and management of software
# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
修改
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
第一列:用户
第二列:host
第三列:可以切换到这个用户
第四列:命令
上面表示:root用户可以在所有主机上登录,拥有所有用户的所有命令权限。
如果想实现以上需求,可以按照以下配置:
ftpadmin ALL=(root) /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/groupadd, /usr/sbin/groupadd, /bin/passwd
解读:ftpadmin用户可以在所有主机上登录,拥有root用户的useradd,userdel, groupadd,groupdel,passwd这些命令的权限。
## 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