Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a website that writes files when necessary. Those files are owned by www-data. I also have my user, which executes an application to gather information from those files. It is written in Python. However, since those files are owned by www-data, my application can't read them, and I have to execute the application as root, which I'd prefer not to do. What can I do to allow my user read the files that www-data create?

EDIT, relative to comments:

-rw-r--r-- 1 ivan www-data 444 2011-07-20 16:34 serverfile1.php
-rw-r--r-- 1 ivan www-data 140 2011-07-20 16:34 serverfile2.php
-rw-r--r-- 1 ivan www-data 478 2011-07-20 16:35 serverfile3.php
-rw-r--r-- 1 www-data www-data 10 2011-07-20 17:41 info1.txt
-rw-r--r-- 1 www-data www-data 21 2011-07-20 17:41 info2.txt
-rw-r--r-- 1 ivan www-data 236 2011-07-20 16:35 serverfile4.php

I still can't read the files info1 and info2 using the user ivan

share|improve this question

4 Answers 4

up vote 3 down vote accepted

Add your user to www-data group and make the files group-readabe.

# usermod -a -G www-data username
# chmod -R g+r /var/www/files
share|improve this answer
1  
The files may already be group-readable. If not you may want to Fix apache's umask -- See this question on SO: stackoverflow.com/questions/428416/… –  voretaq7 Jul 20 '11 at 15:38
    
-rw-r--r-- 1 ivan www-data 444 2011-07-20 16:34 serverfile1.php -rw-r--r-- 1 ivan www-data 140 2011-07-20 16:34 serverfile2.php -rw-r--r-- 1 ivan www-data 478 2011-07-20 16:35 serverfile3.php -rw-r--r-- 1 www-data www-data 10 2011-07-20 17:41 info1.txt -rw-r--r-- 1 www-data www-data 21 2011-07-20 17:41 info2.txt -rw-r--r-- 1 ivan www-data 236 2011-07-20 16:35 serverfile4.php i can't still read the files info1 and info2 using the user ivan –  Ivan Jul 20 '11 at 15:42
    
please post the output of the command: "groups ivan". –  HUB Jul 20 '11 at 16:04
    
By asking for output I want to make shure that you have added "ivan" to group "www-data". Of course, you shouldn't copy '#' symbols to your command line. And "/var/www/files" should be the way to YOUR files... –  HUB Jul 20 '11 at 16:12
    
root@sv1:/home/ivan# groups ivan ivan : ivan www-data –  Ivan Jul 20 '11 at 16:13

Assuming that file perm listing is accurate, the user ivan should have access to those files.

You may want to verify the mode that you are opening the file in with Python. If you attempt to open it with write priveleges, you will receive errors.

If, as ivan, you can cat or head the info1/info2 files its more likely to be a python/code issue.

share|improve this answer

Your files are already group readable, if you are only opening the files for read than you shouldn't have any problems. Some of these were already suggested but here are things to check.

  1. The Python code is opening for read and not write
  2. Ensure the directory the files are in are both readable and executable (at least executable) by world.
  3. Test using cat via the user Ivan, if it works its a problem with the python code.
share|improve this answer

An alternative would be running php as fastcgi under a specific user (php fastcgi+suexec).

bye, stefano

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.