简体   繁体   中英

Permission inheritance of directories in Linux

So by default my / directory is chmod 555 . I ran the following to test something out:

sudo chmod 777 /
mkdir /dss
sudo chmod 555 / # reset permissions

if I run stat /dss then it shows

  File: ‘/dss’
  Size: 6               Blocks: 0          IO Block: 4096   directory
Device: 10302h/66306d   Inode: 5802557     Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1001/ssm-user)   Gid: ( 1002/ssm-user)
Access: 2021-06-30 22:01:44.478434800 +0000
Modify: 2021-06-30 22:01:44.478434800 +0000
Change: 2021-06-30 22:01:44.478434800 +0000

I expected /dss to inherit 777 permissions from / at the time it was created? And if I create any subdirectories under /dss , they're all 755. What's happening here?

You are matching two different things in this question, chmod is a command to set the permissions for a specific path or file, you can do it recursively in differents ways but that you are asking is umask value that determinants the permissions given to a file when is created.

If you want to check the value setting, you have to execute the command “umask”, this could tell you the value as default that the user has to create files.

If you want to change the umask value you can run the following command to set it.

umask 022

Keep in mind that the numbers that are you described in the command above are the permissions that won't give to the file, so, in this case, will be generated with 755.

Please refer to the next table.

Number Permission 4 read 2 write 1 execute

This command isn't permanent, once you logout this will be lost and set as default, if you want to change the value in a permanent way you need to set up in “/etc/profile” or “bashrc” and add the command above, you can refer to[1].

BR.

[1] https://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

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