在我的 lubuntu 22.04 上,我需要更改该文件/etc/hosts
。为此,我要执行命令:
> /usr/bin/cp /path/to/new_hosts /etc/hosts
由非 root 用户在没有 sudo 命令的情况下执行。为此,我将以下行添加到文件中/etc/sudoers
:
<username> ALL = (root) NOPASSWD: /usr/bin/cp /path/to/new_hosts /etc/hosts
/etc/sudoers
我已经检查了命令的正确语法:
> sudo visudo -c /etc/sudoers
该命令的输出是:
/etc/sudoers: parsed OK
/etc/sudoers.d/10-installer: parsed OK
/etc/sudoers.d/README: parsed OK
/etc/sudoers.d/kdesu-sudoers: parsed OK
该消息/etc/sudoers: parsed OK
向我保证 的语法/etc/sudoers
是正确的。
当我cp
通过终端执行命令时,结果是Permission denied
。
错误在哪里?
您需要使用以下命令运行命令
sudo
:否则,该
sudoers
文件将不会被考虑。