这个文件必须用'visudo'命令编辑。?

Ank*_*kit 12 sudoedit

为什么建议/etc/sudoers使用visudo命令编辑文件?这是该文件的示例:

## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.
Run Code Online (Sandbox Code Playgroud)

有什么特殊原因吗?

Ulr*_*gel 18

因为visudo检查语法并确保它是有效的配置文件;否则,您可能会编辑该文件,出错并且 sudo 将不再可用,因为您的语法错误。


Flu*_*lup 18

除了前面提到的语法检查之外,visudo还会锁定,/etc/sudoers以便两个用户不能同时对其进行编辑。同时尝试编辑将给出

visudo: /etc/sudoers 忙,请稍后再试


jor*_*anm 8

这样做的原因是visudo将在覆盖当前 sudoers 之前验证文件没有语法错误。这可以防止您意外地将自己锁定在 root 之外。