# Sudo root, to make a chown

**URL:** <https://www.ruby-forum.com/t/sudo-root-to-make-a-chown/144433>\
**Category:** Rails\
**Created:** [July 29, 2008, 5:29pm UTC](https://www.ruby-forum.com/t/sudo-root-to-make-a-chown/144433 "2008-07-29T17:29:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [July 29, 2008, 5:29pm UTC](https://www.ruby-forum.com/t/sudo-root-to-make-a-chown/144433/1 "2008-07-29T17:29:32Z")

</div>

Hello,

I’m trying to do a rsync on a folder generated by ruby on Rails.  
But the main problem is that every generated stuff is nobody nobody.

So I’m trying to chown, but the ruby service through apache is not root.

So I wonder how can I execute action as a root.  
Is there any sudo stuff in ruby so I can do my chown on my files an  
directories, then an rsync.

Thanks

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [July 29, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/sudo-root-to-make-a-chown/144433/2 "2008-07-29T20:55:05Z")

</div>

Hi David,

> I’m trying to do a rsync on a folder generated by ruby on Rails.  
> But the main problem is that every generated stuff is nobody nobody.
> 
> So I’m trying to chown, but the ruby service through apache is not root.
> 
> So I wonder how can I execute action as a root.  
> Is there any sudo stuff in ruby so I can do my chown on my files an  
> directories, then an rsync.

You can execute commands in Ruby using backticks (e.g. `sudo chown`) but  
I think the truly solution lies in fixing the permissions in the first  
place. Try to configure the user that the Rails instance runs as. How to  
do that depends on if you’re using FastCGI, Mongrel or mod\_rails.

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [July 29, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/sudo-root-to-make-a-chown/144433/3 "2008-07-29T21:13:14Z")

</div>

> You can execute commands in Ruby using backticks (e.g. `sudo chown`) but  
> I think the truly solution lies in fixing the permissions in the first  
> place. Try to configure the user that the Rails instance runs as. How to  
> do that depends on if you’re using FastCGI, Mongrel or mod\_rails.

I’ve tried system() but as the process is not root root I can’t change  
the right to root root.

I’m using mod\_rails. My rsync is into an action of a controller.

How can I set default file creation root root for a virtual host ?  
I’m not familiar with apache and mod\_rails.

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [July 29, 2008, 10:40pm UTC](https://www.ruby-forum.com/t/sudo-root-to-make-a-chown/144433/4 "2008-07-29T22:40:52Z")

</div>

David N. wrote:

> I’m using mod\_rails. My rsync is into an action of a controller.
> 
> How can I set default file creation root root for a virtual host ?  
> I’m not familiar with apache and mod\_rails.

Check out the user switching and default user configuration options in  
the mod\_rails documentation.  
Reading up on Apache configuration will be required unless you outsource  
it 🙂

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.
