0

I've added ubuntu user to the www-data group and set the folder permissions as follows:

sudo gpasswd -a "$USER" www-data
find /var/www -type f -exec chmod 0640 {} \;
sudo find /var/www -type d -exec chmod 2750 {} \;

I can verify that ubuntu has been added to the group (running groups shows ubuntu www-data). I can access and read any files and directories in the /var/www directory as ubuntu.

I want to grant write permissions to ubuntu user in certain directories. Running sudo chmod -R g+w /var/www/public/uploads/ gives ubuntu access to write into this folder.

The problem is that when www-data creates new directories in /var/www/public/uploads/, ubuntu does not have permission to write in these newly created directories.

That is, when www-data creates /var/www/public/uploads/some-new-folder/, ubuntu cannot touch files in some-new-folder.

How can I change the permissions so that any files and directories created by www-data in specific paths will be writable by ubuntu as well?

  • This may help: serverfault.com/questions/383734/… – LinuxNinja Jan 28 '16 at 6:38
  • I tried setting umask to 002 in /etc/apache2/envvars, restarted Apache, also searched for other solutions involving setting the umask. Nothing worked so far, www-data user keeps creating new directories with drwxr-sr-x permissions instead of drwxrwsr-x. – Arman H Jan 28 '16 at 8:27
0

You could use the "setgid" bit of the parent folder ("uploads", in this case) and any file created within it will have the specified group membership regardless of the creator. The command is below. Here is a good post I found on "setgid": http://www.toptip.ca/2010/03/linux-setgid-on-directory.html

Setgid with chmod: sudo chmod g+s /var/www/public/uploads/ <your group>

Hope that helps!

  • Thanks for the reply. This works to change existing directories to be writable, but any new directories created by www-data user are still not writable by ubuntu. New folders have drwxr-sr-x permissions. So even though the shared group ID is present, group users still cannot write to this path. – Arman H Jan 28 '16 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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