Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that is run sometimes via the web, sometimes via the command line. When the script is run via web, it's run via user www-data. When it's run via command line, it's run via user jason.

This script writes to a directory called cache.

  • If I chown -R jason cache, I can run the script as jason but not www-data. This makes sense.
  • If I chown -R www-data cache, I can run the script as www-data but not jason. This also makes sense.

I tried creating a group called scripts, adding my two users, then chowning cache to scripts. I'm not really sure how to do the last part, the chowning part. The Linux command docs I've found online for this are astoundingly bad.

I don't know if I explained this all that well but hopefully it's clear what I'm trying to do. Any advice would be appreciated.

share|improve this question
up vote 1 down vote accepted

Usually with chown you'd do:

chown user:group (files)

Is that not working? Can you check and make sure the files are owned by the group, and that the second group of permissions is at least r-x?

-rwxr-xr-x 1 user group 44380 2009-02-10 13:10 junk

share|improve this answer
drwxrwxrwx 4 jason scripts 4096 2010-12-21 11:20 cache – Jason Swett Dec 21 '10 at 16:21
That looks fine. It seems that the problem is this: if jason creates a file, then later www-data wants to overwrite that file, it can't do it. – Jason Swett Dec 21 '10 at 16:21
@jason swett: When he's creating it, I assume he's creating it jason:jason, rather than jason:scripts – Satanicpuppy Dec 21 '10 at 16:26
Okay, it turns out if I delete any of those files before I try to open them, they can be opened by either user. – Jason Swett Dec 21 '10 at 16:30
You need to look at warner's setuid line: chmod g+s directory This will force the files created in the directory to inherit the directories group. That should solve the permission issue. – Satanicpuppy Dec 21 '10 at 16:33

You can use chgrp or chown when specifying user:group instead of just user.

You will likely want to specify the SGID bit, so as that the group ownership is maintained on creation. You can do this using chmod g+s directory.

You will also need to insure that the write and execute bits are set for the group, which can be done with chmod g+wx.

share|improve this answer

Your Answer


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.