Setting Default Permissions for Newly Created Files and Sub-Directories Under a Directory in Linux

Setting default permissions for newly created files and sub-directories under a directory in Linux?

To get the right ownership, you can set the group setuid bit on the directory with

chmod g+rwxs dirname

This will ensure that files created in the directory are owned by the group. You should then make sure everyone runs with umask 002 or 007 or something of that nature---this is why Debian and many other linux systems are configured with per-user groups by default.

I don't know of a way to force the permissions you want if the user's umask is too strong.

How do I change permissions for a folder and its subfolders/files?

The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Some splainin': (thanks @tobbez)

  • chmod 755 {} specifies the command that will be executed by find for each directory
  • chmod 644 {} specifies the command that will be executed by find for each file
  • {} is replaced by the path
  • ; the semicolon tells find that this is the end of the command it's supposed to execute
  • \; the semicolon is escaped, otherwise it would be interpreted by the shell instead of find

Apply directory permissions to all new subdirectories in linux

Most unix command come with a recursive option. In this case:

-R, --recursive

It seems like you are trying to use this, but you have -Rm. That is not the correct option.

I think what you need is:

sudo setfacl -R -m g:users:rwX,d:g:users:rwX index/

I typically use chmod instead of setfacl.

chmod -R 777 *

Linux file default permissions

For changing default permissions of the file created, you can use umask command. umask is user mask which is used whenever a new file is created.

umask is a three digit number with octal base. First digit decides the user permissions, second is for group while third determines the permissions for others.

umask value is used in inverted/complemented form though. That means to determine the required umask value for the permissions you want, subtract the permissions (in octal form) from 666. The result should be used as your umask value. e.g. if you want to set default permissions to rw-r--r-- (which is 644 in octal) subtract 644 from 666. The result (022) is your umask value.

To set value for umask you can simply use:

umask 022

command.

For your case here, I think you can use

umask 000

CentOS change permissions of newly created folders

Set may set a correct umask.

You can find extra documentation at http://centoscert.com/content/what-umask-and-how-setup-default-umask

You can modify the one in /etc/profile (replace 022 by 002) if you want to change for the whole system.

But careful, this also impact access rights of 'standard' files (not only folders).



Related Topics



Leave a reply



Submit