# sudo root, to make a chown

**URL:** <https://discuss.rubyonrails.org/t/sudo-root-to-make-a-chown/32522>\
**Category:** rubyonrails-talk\
**Created:** [July 29, 2008, 6:55pm UTC](https://discuss.rubyonrails.org/t/sudo-root-to-make-a-chown/32522 "2008-07-29T18:55:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 29, 2008, 6:55pm UTC](https://discuss.rubyonrails.org/t/sudo-root-to-make-a-chown/32522/1 "2008-07-29T18: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.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 29, 2008, 7:13pm UTC](https://discuss.rubyonrails.org/t/sudo-root-to-make-a-chown/32522/2 "2008-07-29T19: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:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 29, 2008, 8:40pm UTC](https://discuss.rubyonrails.org/t/sudo-root-to-make-a-chown/32522/3 "2008-07-29T20:40:52Z")

</div>

David Nguyen 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 🙂
