You can accomplish this via nuances of owner and group permissions. From my understanding, OSX is linux-like?
If you don't care if users can create files or folders you can chown
all the files to a user other than them, which prevents them from being able to chmod themselves execution permission. If the files are 664 root:users
and the user is in the users group, they can edit the file at will.
To prevent the user from creating a file (and thus owning it able to chmod
it 7xx), you can chown
the directories to a different user, say chown staff:users directory
. For this, you need a "staff" user. You could chmod 555
(or 551 or 550) the directories and 664 the files. But that's not very usable... dirs need to be executable to cd
to them, readble to ls
them, and writable to create or delete files and subfolders. This policy is somewhat draconian.
Or make chmod
and chown
such that normal users cannot run them to make their own files executable. Someone in "staff" group can use it but not general users, which is an ok compromise:
# From:
/bin$ ls -alh ch*
-rwxr-xr-x 1 root root 59K Jan 26 2013 chgrp
-rwxr-xr-x 1 root root 55K Jan 26 2013 chmod
-rwxr-xr-x 1 root root 63K Jan 26 2013 chown
# To:
/bin$ ls -alh ch*
-rwxrwx--- 1 root staff 59K Jan 26 2013 chgrp
-rwxrwx--- 1 root staff 55K Jan 26 2013 chmod
-rwxrwx--- 1 root staff 63K Jan 26 2013 chown
Research using umask
to see if there's a way you can prevent users from creating a file with execute permissions set, which when combined with the above file permissions, can do away with the silly ownership of their directories.
Pay attention to cascading effects when playing with permissions and try to envision all ways something can go wrong or be defeated. Hack yourself to see what happens.
The best flexibility is combining some of the above with careful use of the owner and group "sticky" bits. They can be set so that when users create files or directories, they "stick" with the inherited ownership. I do this with the shared RAID on our Samba server so my Windows people have a proper experience.
The find
command is a powerful tool to help do the above:
Change all subdirs from 500 to 770 permissions (to repair a previous chmod -R
screw up):
find . -type d -perm 500 -print0 | xargs -0 chmod 770
Change all files below (and subdirs) with permissions 644 to 664, which gives group permission to edit files: awesome for web server files edited from Windows on a Samba share:
find . -type f -perm 644 -print0 | xargs -0 chmod 664