Linux嵌套目录权限的比较探究

在/tmp目录下新建一个嵌套目录,名字分别为test_0、test_1、test_2。在test_2目录下新建普通文件,名为tryme。设置test_0和test_2的权限为777,设置test_1的权限为700,tryme文件的权限为777,问tryme这个文件能否被读取?

1 cd /tmp
2 mkdir -p test_0/test_1/test_2
3 touch test_0/test_1/test_2/tryme
4 chmod 777 test_0/
5 cd test_0
6 chmod 700 ./test_1/; chmod 777 ./test_1/test_2/; chmod 777 ./test_1/test_2/tryme
[linuxprobe@linuxprobe test_0]$ ll -d; ll -R
drwxrwxrwx. 3 linuxprobe linuxprobe 19 Apr 27 10:55 .
.:
total 0
drwx------. 3 linuxprobe linuxprobe 19 Apr 27 10:55 test_1

./test_1:
total 0
drwxrwxrwx. 2 linuxprobe linuxprobe 18 Apr 27 10:56 test_2

./test_1/test_2:
total 0
-rwxrwxrwx. 1 linuxprobe linuxprobe 0 Apr 27 10:56 tryme
$ su - zhangsan
Password:
Last login: Wed Apr 27 08:46:08 CST 2022 on tty3
[zhangsan@linuxprobe ~]$ cat /tmp/test_0/test_1/test_2/tryme
cat: /tmp/test_0/test_1/test_2/tryme: Permission denied

答案是不能,因为目录的权限是一层层读取的,嵌套目录中只要有一层目录的权限设置不正确,就会影响下级目录和文件。

如果把目录test_1的权限设置为701,tryme能否读取呢?(事先已经用linuxprobe用户编辑好了一段话:This is a message from user ‘linuxprobe’

1 [zhangsan@linuxprobe ~]$ su - linuxprobe
 2 Password:
 3 Last login: Wed Apr 27 10:52:32 CST 2022 on :0
 4 [linuxprobe@linuxprobe ~]$ cd /tmp/test_0/
 5 [linuxprobe@linuxprobe test_0]$ chmod 701 test_1/
 6 [linuxprobe@linuxprobe Desktop]$ su - zhangsan
 7 Password:
 8 Last login: Wed Apr 27 11:18:50 CST 2022 on pts/0
 9 [zhangsan@linuxprobe ~]$ cd /tmp
10 [zhangsan@linuxprobe tmp]$ cat test_0/test_1/test_2/tryme
11 This is a message from user 'linuxprobe'.

总结:在嵌套目录中,各上层目录有x权限的情况下,就可以对最底层的文件做出cp cat等命令。

Original: https://www.cnblogs.com/randyszone/p/16198255.html
Author: randy198
Title: Linux嵌套目录权限的比较探究

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/583094/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球