3

is there a way to automatially set sudo chmod 777 for all the files, folder and subfolders in a directory. The sudo chmod 777 should automatically be set when a folder or a file is created in the parent directory.

Is there a way to do that?

2
  • see this post superuser.com/questions/151911/…
    – Bibi424
    May 29, 2014 at 12:14
  • Are you sure that you are solving the right problem? I assume that chmod 777 is a means to an end? Perhaps there is another way towards that end?
    – andol
    May 29, 2014 at 12:26

2 Answers 2

3

In bash execute umask 000 and then every directory you create will have permissions 777 and every file you create will have permissions 666. You can't create executable files by default, you need to explicitly make them so using chmod. It is a security feature.

Note that the umask is "bitwise xor" of the desired file permissions and to get the most permissive mode of 777 you need to use umask 000.

In recent Ubuntu systems you set the systemwide umask in file /etc/login.defs. Older systems use /etc/profile.

Please do have in mind that people who create operating systems know a thing or two about security and have chosen umask 022 for a reason. You will make your computer quite insecure if you follow this advice.

3

One way that comes to mind is the setfacl command. Here's an Ubuntu guide on how to enable ACL (access control lists) for a mount point. To summarize, install the relevant package

sudo apt-get install acl

then, add the option 'acl' to the mount point in /etc/fstab

UUID=07aebd28-24e3-cf19-e37d-1af9a23a45d4 /home ext4 defaults,acl 0 2

finally, remount the drive so the changes take effect

sudo mount -o remount /home

After doing this, you can use the setfacl and getfacl to set options for any directory or file in particular. ACL options for directories also include the ability to set default permissions for new files and subfolders with commands like the following:

setfacl -d -m u::rwx /folder/to/modify  # Default permissions for owning user
setfacl -d -m g::rwx /folder/to/modify  # Default permissions for owning group
setfacl -d -m o::rwx /folder/to/modify  # Default permissions for others

For reference, here's the man page for setfacl. Also, while these permissions will apply by default to newly-created sub-files and folders, setfacl can still be used to change the rights after the fact if desired. Finally, after enabling ACLs, you can see which files/folders have an ACL replied in the output of your ls -l command by looking for a + symbol after the permissions. For example,

-rw-r--r--+  # Has ACL applied
-rw-r--r--   # No ACL applied
2
  • Compared to @sMurf's answer, this may be a bit like using a sledgehammer on a tack. May 29, 2014 at 12:28
  • umask affects all folders, which can be quite a security hazard; +1 for the ACL suggestion and elaborate description. May 29, 2014 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .