Files saved by my web application has different file permissions from parent
I have a folder in which new subfolders and files will be created automatically, by a script.
I want to maintain the user and group permissions recursively for all new folders and files placed in the parent directory. I know this involves setting a sticky bit, but I can't seem to find a command that shows exactly what I need.
This is w开发者_Go百科hat I have done so far:
sudo mkdir -p /path/to/parent
sudo chmod -R 660 myself:somegroup /path/to/parent
Thereafter, I want the 660 permissions to be set recursively to any folders and files placed in /path/to/parent
However, whenever Apache saves a folder/file it assigns it permissions of 700 with user and group set to the apache user. This is NOT what I want. I want all files/subfolders under the parent to have 660 permissions for myself:somegroup.
Actually the octal flag 660 is probably not even correct. The permissions I want are:
- Directories placed under /path/to/parent are eXecutable by users with permissions
- files are read/writeable by user myself and members of somegroup
- Files and folders in /path/to/parent is NOT world readable
Can someone help please?
I am running on Ubuntu 10.0.4 LTS
sudo mkdir -p /path/to/parent sudo chmod -R 660 myself:somegroup /path/to/parent
erm - not ideal.
If you want new files/dirs created to have the same group ownership you need to set the group sticky bit on directories
find /path/to/parent -type d -exec chmod g+s {};
And you need to make directories executable:
find /path/to/parent -type d -exec chmod ug+x {};
...
However, whenever Apache saves a folder/file it assigns it permissions of 700 with user and group set to the apache user
Then you also need to set the umask (0770) for the executing code (or directly change the permissions) and ensure the apache uid is a member of somegroup. IIRC to set the group sticky bit, umask should be 2770 - but do check the manual.
You can set apache to write new files with specific umask.
Todo so in RedHat/CentOS edit the file /etc/sysconfig/httpd, and change to:
umask 007
In debian/Ubuntu use the file /etc/apache2/envars with the same settings
精彩评论