Link to home
Start Free TrialLog in
Avatar of burnsj2
burnsj2

asked on

CentOS / Linux Chown / Ownership Troubles

I have a user, ftpuser, in a group ftpgroup.  I am running apache. A user uploads some files through the website.  I have apache create a directory in /home/ftpuser and then the files copy there.  This part works.  Now this newly created directory, say, "newdir" is owned by apache.  I want apache to chown /home/ftpuser/newdir to ftpuser:ftpgroup so the ftp users can access the files.  

When I try to do this:
sudo -u apache chown ftpuser:ftpgroup /home/ftpuser/newdir

I get "chown: changing ownership of `/home/ftpuser/newdir': Operation not permitted".

Also, for apache to create the "newdir" directory at all, /home/ftpuser has to have 777 permissions.  Obviously there has to be some way to do this without going to 777.

Thanks,
Avatar of BELRpR
BELRpR

Are you using php for the site?

Else you could use the php function to change ownership http://be.php.net/chown. Also add the apache user to the ftpgroup if you want apache to still "control" the file too.
If you want all the files in a given directory to be owned by a single group as they are created,  use sticky bits on the directory.  For example,  if you change the directory group to be ftpgroup and then change the directory to:

  chmod 2775

(Note the extra 2)  every file created in this directory will be owned by Apache but the group will be set to ftpgroup.

Read more.  http://en.wikipedia.org/wiki/Sticky_bit

Avatar of burnsj2

ASKER

BELRpR:
This is not working.  With PHP using chmod via its own function or through the system function it doesn't work.  I have apache in ftpgroup and ftpuser in the apache group.  

Since it fails to change the owner the ftp users cannot access the files.  

mgrennan:
I also tried a file owned by apache but in ftp group.

If I just set all the uploaded files (which are owned by apache) to 777 the ftp users can download them.  It seems every time I try to do permissions the right way in linux I end up just setting everything 777.
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of burnsj2

ASKER

Tintin, that seems to work.  Thanks.