使用 sudo 密码作为参数 [英] Use sudo with password as parameter

查看:34
本文介绍了使用 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 开关使 sudo 从 STDIN 读取密码.这意味着你可以做

The -S switch makes sudo read the password from STDIN. This means you can do

echo mypassword | sudo -S command

将密码传递给sudo

但是,出于安全原因,不涉及将密码作为命令的一部分传递的其他人的建议(例如检查用户是否为 root)可能是更好的想法

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆