Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need that for the folder /var/www when my user testuser creates a file the permissions are g+rwx and the files belong to the group www-data

Any idea of how could I do that ?

Cheers.

EDIT:

I'm creating the files via SSH.

share|improve this question
    
How is your user creating files? Via FTP stor/appe ? Via HTTP PUT? Through a shell account? These details are important, because they greatly affect the possible answers, and need to be in your question. –  JdeBP Jan 23 '12 at 13:06
    
Thanks for the input :), I'm creating everything via SSH. –  Mr.Gando Jan 23 '12 at 13:11
add comment

2 Answers

up vote 6 down vote accepted

To set the group, give /var/www the setgid bit:

chgrp www-data /var/www
chmod g+s /var/www

To also adjust subdirectories: find /var/www -type d -exec chmod g+s {} +

This will make all newly created files inherit the parent directory's group, instead of the user's.


To set the default group permissions, you will have to use ACLs. Set a "default" ACL:

setfacl -m "default:group::rwx" /var/www

To also adjust subdirectories: find /var/www -type d -exec setfacl -m d:g::rwx {} +

Note: The file system must have ACL support enabled. Sometimes it is on by default; on ext3 or ext4 you might get "Operation not supported", in which case it must be enabled manually:

  • For a currently mounted filesystem: mount -o remount,acl /

  • Permanently – one of the methods below:

    • at fstab level: edit /etc/fstab to have acl in the options field

    • at filesystem level: tune2fs -o acl /dev/diskname

share|improve this answer
    
can't you get the subdirectories with chmod -R g+s /var/www? Doesn't seem like you should need the find command. –  bobpaul Jan 14 at 0:56
    
@bobpaul: No, because chmod would also get all files. –  grawity Jan 14 at 3:01
add comment

The group of the files being created by an user is the group of that user (in /etc/group). The permissions are controlled by the UMASK parameter see this

share|improve this answer
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.