/etc/sudoers

/etc/sudoers文件

#

# This file MUST be edited with the 'visudo' command as root.

#

# Please consider adding local content in /etc/sudoers.d/ instead of directly modifying this file.

#

# See the man page for details on how to write a sudoers file.

#

Defaults env_reset

Defaults mail_badpass

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification

root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command

%sudo ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

示例:

hans        ALL=(root)    useradd,userdel

授权hans用户,在所有计算机上,以root身份运行useradd,userdel命令

%smith    ALL=(ALL)        NOPASSWD:useradd,userdel

授权smith组全部成员,在所有计算机上,以所有用户的身份运行useradd,userdel命令,且运行时不必输入密码

讲解:root     ALL=(ALL)        ALL

root表示被授权的用户,这里是root用户;

第一个ALL表示所有计算机;

第二个ALL表示所有用户;

第三个ALL表示所有命令;

全句的意思是:授权根用户,在所有计算机上,以所有用户的身份运行所有命令

/etc/sudoers的通用格式为:

user host=(run_as) command

user:一位或几位用户,在/etc/group中可以用一个%代替它,组对象的名称一定要用百分号%开头。

host:一个或几个主机名,ALL表示可以在所有的主机上

run_as:作为哪个用户运行,常见选项是root和ALL

command:想让用户或组运行的一个或几个根级别命令

原文地址:https://www.cnblogs.com/asnjudy/p/4659475.html