Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 often find myself chown-ing files as I created them through SSH and they are owned by jm:jm for example.

Then to allow Apache to access it, I need to for example do chown jm:www-data.

I am sure I can specify that when I create files, instead of using the group under my name, specify another?

Or is there a better way of managing users/groups?

share|improve this question
up vote 17 down vote accepted

If you want all new files in a particular directory to be owned by a particular group, just apply the setgid bit on it:

chgrp www-data /some/dir
chmod g+s /some/dir

If you have an existing tree of directories that you want to apply this behaviour to, you can do so with find:

find /some/dir -type d -exec chgrp www-data {} +
find /some/dir -type d -exec chmod g+s {} +

(if the directories are already owned by the relevant group, then you can omit the first command in both of these examples).

share|improve this answer
Nice answer! Could you, please clarify what do the symbols ... {} + mean? – Alexander Lomia 2 days ago
They are arguments to the find command, covered in the man page. For the first invocation, it will run the command chgrp www-data, appending a number of results as arguments (rather than invoking the command once for each result as you'd get with {} \;). – James Henstridge yesterday
Thank you for an explanation – Alexander Lomia yesterday

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.