使用sudo与密码参数 [英] Use sudo with password as parameter
本文介绍了使用sudo与密码参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用我的密码作为参数运行sudo的,这样我可以用它的脚本。我试过
I would like to run sudo with my password as parameter so that I can use it for a script. I tried
sudo -S mypassword execute_command
但没有任何成功。有什么建议?
but without any success. Any suggestions?
推荐答案
-S开关使须藤从STDIN读取密码。这意味着你可以做
The -S switch makes sudo read the password from STDIN. This means you can do
echo mypassword | sudo -S command
通过密码须藤
然而,通过其他的建议不涉及传递密码作为命令的一部分,如检查,如果该用户是根可能是出于安全原因,更好的观点
However, the suggestions by others that do not involve passing the password as part of a command such as checking if the user is root are probably much better ideas for security reasons
这篇关于使用sudo与密码参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文