Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want all the files in /var/www directory be owned by nginx.devel. I have performed chmod once and update these files using rsync.

But if I create a new file and then rsync it, it will be owned by user.user and I need to run chmod with sudo privileges on it.

share|improve this question
    
user is not nginx? –  AlberT Aug 13 '09 at 9:29
    
yes. It is different user. –  exquisitor Aug 13 '09 at 9:38
add comment

1 Answer

up vote 3 down vote accepted

You can't. Well, not automatically anyway. You can, however, enforce group permissions, which with careful planning and an appropriate umask, can solve most permissions problems. If you set the setgid bit on the /var/www directory it will ensure that any new files created under it are owned by the devel group.

Note that depending on which flags you use, rsync may override this behavior and replicate the ownership of the source files.

To set the setgid bit:

$ ls -ld test
drwxr-xr-x 2 insyte insyte 4096 2009-08-13 04:39 test
$ chmod g+s test
$ ls -ld test
drwxr-sr-x 2 insyte insyte 4096 2009-08-13 04:39 test

Demo of the behavior:

$ id
uid=1000(insyte) gid=1000(insyte) groups=4(adm),20(dialout),24(cdrom)
$ ls -ld test
drwxr-xr-x 2 insyte backup 4096 2009-08-13 04:39 test
$ touch test/file1
$ ls -l test
total 0
-rw-r--r-- 1 insyte insyte 0 2009-08-13 04:43 file1
$ sudo chmod g+s test
$ ls -ld test
drwxr-sr-x 2 insyte backup 4096 2009-08-13 04:43 test
$ touch test/file2
$ ls -l test
total 0
-rw-r--r-- 1 insyte insyte 0 2009-08-13 04:43 file1
-rw-r--r-- 1 insyte backup 0 2009-08-13 04:44 file2

The effect is recursive as well; any new directories created after you set the setgid bit will also have the setgid bit set.

An alternative to this approach, of course, would be a cron job that runs every minute and fixes the permissions on the files under /var/www/.

share|improve this answer
    
Thanks for this. –  Dave Rickman Aug 13 '09 at 9:59
add comment

Your Answer

 
discard

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.