Forum: Ruby on Rails ruby edit sudo file

1c8a5d8dea6c3e1739f75263687528a2?d=identicon&s=25 saravanan p (Guest)
on 2013-12-23 08:00
(Received via mailing list)
Hello friends

I am trying to edit apache2 https.config file which require sudo
permission
through my ruby scripting.

File.open(local_filename, 'a') { |f| f.write(doc) }

I can open and edit normal file which doesn't require sudo permission.
I am searching around two hours but still not find any solution, Can
anyone
suggest any idea or any links?

Thanks
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2013-12-23 08:29
(Received via mailing list)
On Mon, Dec 23, 2013 at 12:59 AM, saravanan p
<psaravanan11.rails@gmail.com>wrote:

> I am trying to edit apache2 https.config file which require sudo
> permission through my ruby scripting.
>
>
Be very very careful with this. It can easily leave you wide open to a
hack.

Assuming you do really mean a ruby script, and nothing in your Rails
app,
you can set the setuid bit with chmod and chown the script to root. When
it
executes, it will execute with root persmissions.

Given you've not been able to find this information yourself, I'd again
caution you not to do this.
1c8a5d8dea6c3e1739f75263687528a2?d=identicon&s=25 saravanan p (Guest)
on 2013-12-24 08:19
(Received via mailing list)
I am using the below command and now its not asking password but i think
its not a secure way...

      system("echo systempassword | sudo -S ruby example.rb")
      example.rb:
       in this .rb file i am opening my apache2 file and editing
successfully using ruby File class.
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2013-12-25 02:56
(Received via mailing list)
Please don't reply on top (top post). Reply at the bottom so the
conversation can be followed easier.


On Tue, Dec 24, 2013 at 1:18 AM, saravanan p
<psaravanan11.rails@gmail.com>wrote:

>
>>
>> Assuming you do really mean a ruby script, and nothing in your Rails app,
>> you can set the setuid bit with chmod and chown the script to root. When it
>> executes, it will execute with root persmissions.
>>
>> Given you've not been able to find this information yourself, I'd again
>> caution you not to do this.
>>
>>  --
>

That is insecure, yes.

It is possible to use sudo in situations like this, where you don't
really
have user access to type in the password securely.

Sudo can be configured to allow a user to execute a command or a class
of
commands with elevated privileges.

Read the sudoers man page for more information on how to set this up.

Nevertheless, I caution you to avoid this situation. I am unclear *why*
you
need to do this from inside an application.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.