How to make new file permission inherit from the parent directory?
Solution 1:
You do not want to change your system's default umask, that is a security risk. The sticky bit option will work to some extent, but using ACL's is the best way to go. This is easier than you think. The problem with basic ACL's is that they are not recursive by default. If you set an ACL on a directory, only the files inside that directory inherit the ACL. If you create a subdirectory, it does not get the parent ACL unless the ACL is set to recurse.
First, make sure ACLs are enabled for the volume the directory is on. If you have tune2fs
, you can perform the following:
# tune2fs -l /dev/sda1 | grep acl
Default mount options: user_xattr acl
If you don't have tune2fs
, then examine fstabs
:
# cat /etc/fstab
/dev/system/root / ext3 defaults 1 1
/dev/system/home /home ext3 defaults 1 2
/dev/storage/data /data ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
The 4th column that says "defaults" means on my system (CentOS 5.5), ACL's are on. When in doubt, leave it as defaults. If you try to set the ACL and it errors out, go back and add the acl option to /etc/fstab right after defaults: defaults,acl
.
From what I understand, you want everyone in the users group to have write access to the data directory. That's accomplished by the following:
setfacl -Rm g:users:rwX,d:g:users:rwX data/
Solution 2:
Marking a directory setgid (g+s
) will make new files inherit the group ownership of the directory, but the -g
option of rsync will attempt to override this.
Solution 3:
Other answers apply in a general case, but as you mention that rsync is a source of the problem, you may just need to tune its invocation.
For a start, the popular -a
flag makes rsync copy permissions; use -r
istead of -a
or add -no-p
(for no permission sync) and -no-g
(for no group sync). Also rsync supports --chmod
flag to alter permissions on newly created files.