簡體   English   中英

以非交互方式執行 sudo 命令

[英]Execute sudo command non-interactively

我想在沒有交互的情況下執行以下命令:

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:[sudo] password for tester: 我怎么能從答案的前面剪掉那部分?

謝謝!

將以下行添加到您的/etc/sudoers文件以打開無密碼 sudo。 在這種情況下,我使用john作為登錄帳戶。 更改為您自己的帳戶 ID。

john ALL=(ALL:ALL) ALL

或者,也許更好的是將該行放入名為/etc/sudoers.d/john的文件中。

我會回答我的問題——也許其他人會需要它:

(echo 'clouduser' | sudo -Si >/dev/null 2>&1); sudo grep -e test /etc/sudoers

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM