Permanent user permission

1

1

I have a folder in which periodically files are stored with 755 permission by the root user. I'd like the user 'www-data' to have full permission to all of the files. I used chown, but when a new file is added by the root user I have to re-do it.

The files are added through a BTsync daemon that's run by the root user. I couldn't figure out how to run it as www-data.

Is there a way to give the www-data user permanent access to the folder?

Niek

Posted 2013-11-17T15:24:03.510

Reputation: 183

Answers

0

You may not be able to change the user ownership of every new file created in a particular folder to www-data. But you can change the group ownership of every new file created in a particular folder to www-data by setting the setgid flag of the directory.

nifty:~# whoami
root
nifty:~# mkdir foo
nifty:~# chown www-data:www-data foo
nifty:~# chmod g+s foo
nifty:~# ls -l
total 4
drwxr-sr-x 2 www-data www-data 4096 Nov 17 21:49 foo
nifty:~# touch foo/hi.txt
nifty:~# ls -l foo
total 0
-rw-r--r-- 1 root www-data 0 Nov 17 21:52 hi.txt

Note that you cannot change the user ownership of the new files created in a particular folder automatically because setting the setuid flag on a directory has no effect.

nifty:~# mkdir bar
nifty:~# chown www-data:www-data bar
nifty:~# chmod a+s bar
nifty:~# ls -l
total 8
drwsr-sr-x 2 www-data www-data 4096 Nov 17 21:54 bar
drwxr-sr-x 2 www-data www-data 4096 Nov 17 21:52 foo
nifty:~# touch bar/hi.txt
nifty:~# ls -l bar
total 0
-rw-r--r-- 1 root www-data 0 Nov 17 21:54 hi.txt

Susam Pal

Posted 2013-11-17T15:24:03.510

Reputation: 1 255

Thanks! I was wondering if it's also possible to chmod the newly added files to 766 automatically. – Niek – 2013-11-17T16:48:22.703

It's not possible to change the permissions of newly added files within a particular directory only without using ACLs. However, you can temporarily change umask in your shell or the program or script creating files to set the permissions of new files created anywhere on the file system to 666 automatically with the command: umask +rwx. – Susam Pal – 2013-11-17T17:14:09.937

Thank you! I ended up using ACLs. This answer is very informative

– Niek – 2013-11-17T18:05:33.467