在Ruby on Rails应用中执行sudo命令 [英] Execute a sudo command in Ruby on Rails app

查看:51
本文介绍了在Ruby on Rails应用中执行sudo命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Ruby on Rails应用程序执行以下命令:

I am trying to execute a command like this from a Ruby on Rails app:

sudo服务squid3重新启动

sudo service squid3 restart

如果我尝试使用此代码:

If i try it with this code:

output = ´sudo service squid3 retsart´

它不起作用,在控制台中,我看到linux询问密码. 如何使用此命令传递密码?或其他建议...

It don't work, in the console i see that linux asks the password. How can i pass a password with this command? Or other suggestions...

推荐答案

如果系统上可用,请尝试使用sudo -S标志(请检查man):

You can try the sudo -S flag if available on you system (check man):

echo secretPasswd | sudo -S service squid3 restart

这意味着密码将是透明的,因此您可以将需要执行该任务的用户添加到sudoers中(顺便说一句,这会引起另一个安全问题).

This means that the password will be in clear so you can add the user which needs to perform the task to the sudoers (which creates another security issue by the way).

这篇关于在Ruby on Rails应用中执行sudo命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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