0

我想在没有交互的情况下执行以下命令:

sudo grep -e "test" /etc/sudoers

我尝试了以下方法:

tester@compute:~$ echo 'clouduser' | sudo -S grep -e "test" /etc/sudoers
[sudo] password for tester: test ALL=(ALL) NOPASSWD: ALL

问题是我得到[sudo] password for tester: 了响应。我怎样才能从答案的前面剪掉那部分?

谢谢!

4

2 回答 2

1

我会回答我的问题 - 也许其他人会需要它:

(echo 'clouduser' | sudo -Si >/dev/null 2>&1); sudo grep -e test /etc/sudoers
于 2020-09-16T07:08:34.423 回答
0

将以下行添加到您的/etc/sudoers文件中以打开无密码 sudo。在这种情况下,我使用john作为登录帐户。更改为您自己的帐户 ID。

john ALL=(ALL:ALL) ALL

或者,也许更好的是将该行放入一个名为/etc/sudoers.d/john.

于 2020-09-11T14:53:29.363 回答