简体   繁体   中英

Linux permission in directories

I installed Apache in my server and it all looks fine. The problem is that everytime I create a folder/file it does not have 777 permission, I need to use chmod to every folder/file I create to assign 777 permission. How can I create a permission rule that will be the default to new files/folders ?

The short answer is that you can't and you shouldn't even if you could. Having any file on the file system with 0777 as the mode is a very bad idea.

The slightly longer answer is that the Apache process controls the mode that it creates new files with as the third argument to open(2) or by using fopen(3) . In the latter case, the mode is 0666 by default. Whatever mode is passed in is further modified by the process's umask value. If a process has a sane umask (such as 022 ), then the result of opening a file with fopen will be a file with its mode set to 0666 & ~022 = 0644 . I guess if the process were to use open to create a file with 0777 and the process umask was set to 0 , then the file that it creates would have 0777 as the resultant mode.

While I agree 777 is not a good idea, the answer is umask:

umask 000

I recommend the following at least so not everyone in the world (well, with access to that machine) can write there:

umask 002

Oh, and these don't inherit by the directory. Use ACLs instead to get inheritence. ACL tools vary from OS to OS. Try "setfacl" or "chacl".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM