/etc/sudoers文件是Linux系统中用于配置sudo命令的一个文件。sudo命令允许具有适当权限的用户以超级用户(root)或其他用户的身份执行命令。/etc/sudoers文件决定了哪些用户可以使用sudo,以及它们可以执行哪些命令。
sudoers文件通常位于/etc/sudoers,这个文件建议通过visudo命令进行编辑,因为使用visudo命令会在保存前检查文件的语法错误,防止因配置错误导致系统无法正常使用。
[root@patrolagent ~]# visudo
>>> /etc/sudoers: syntax error near line 1 <<<
What now?
Options are:
(e)dit sudoers file again
e(x)it without saving changes to sudoers file
(Q)uit and save changes to sudoers file (DANGER!)
What now? e
[root@patrolagent ~]#
1.sudoers文件基本语法
sudoers文件中的每一行通常遵循以下格式:
user host=(runas) command
其中:
user:允许执行命令的用户或用户组。E.g:patrol
host:规则使用的主机(通常设置为ALL,表示适用于所有主机)。E.g:ALL
runas:允许以哪个用户身份运行命令,通常是root。E.g:ALL
command:允许执行的命令或命令的路径。可以使用ALL来表示所有命令。E.g:ALL
[root@patrolagent ~]# cat /etc/sudoer