Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a directory with full permissions (which also applies to its "sub folders"). I am using following command:

 sudo chmod 777 -R /opt/www

It sets permissions only to existing folder and subfolders only. I want to make it applicable to new files/folder also so that I don't need to type in the same command again and again for new files and folders. Kindly let me know the complete Syntax.

share|improve this question

migrated from Dec 8 '11 at 11:31

This question came from our site for professional and enthusiast programmers.

chmod 777 is wrong in like 99.99% of scenarios. And of course it's wrong to host a site in a word writeable directory. Also, try getting rid of word "kindly" in technical questions, it makes a lot of people think "cheap India / send me codez" and ignore them. – vtest Dec 8 '11 at 15:17
@vtest agreed 777 should rarely if ever be used especially in a production environment. – Lamar B Dec 9 '11 at 8:28

Checkout the umask settings. You can set it once with the command "umask", but if you want to keep it permanently, you have to include it in .bashrc, .profile, ... or whatever you use.

There is also a setting for the pam login technique. (/etc/pam.d)

I have for example in /etc/pam.d/common-session:

optional               umask=002

But that's now really going into detail; I would need to know more about your system.

To get "local" umasks, there is also a mount option umask, that only changes the umask for this device. However, this only is true for certain filesystems, like FAT.

On umsaks and access rights: As vtest pointed out, 777 is not a good choice for access rights and usually not needed. With the umask 002 the group gets write-permition. The reason to do this is, now you can give the dir. a group-ownership of your choice and set it's rights to 2775 (that is rwxrsxr-x). The group-s (or 2000) means, that each created file or dir. will again belong to this group and so be writeable by all in that group).

share|improve this answer
Remember that umasks are a system-wide (PAM) or user-wide (.profile) setting, not per directory. Might work for the OP, but as he wrote of one directory, it probably does not. – thiton Dec 8 '11 at 11:51
Right. But that's the trade: either you do it "global" or you use the more complex and not compartible (=traditional) ACL. There are no lokal umasks. (with the mount exception, I now edited into my post) – Nikodemus Dec 8 '11 at 12:38

File access control lists (FACLs) are your friend: man getfacl.

share|improve this answer

You cannot. POSIX file permissions in linux are not inheritable. They are given by the creating process and umask.

If you are really desperate about it , write a daemon process that monitors the directory and sets file permissions accordingly. Of course, this would imply that the daemon runs with sufficient access, e.g. as root .

Otherwise you can

setfacl -d -m u::rwX,g::rwX,o::- /path/to/parent

but the your permissions will not be POSIX anymore.

share|improve this answer
file permissions in *nix are semi-inheritable by setting the sticky bit. Set a group ownership of the parent and the children will inherit if members of said group will use this group for all newly created files. – Lamar B Dec 9 '11 at 8:04

Create a group called webadmin or similar then add all users that need access to this group. Set the directory permissions for the /opt/www directory to sticky group R/W and the group to webadmin. This will create all new files as group webadmin and set them to be read and write for the group. Because, all the need accounts are members of webadmin they will have access to the files.

share|improve this answer

You must log in to answer this question.