ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2022-04-27 14:34:00  阅读:235  来源: 互联网

标签:tmp linuxprobe 27 Apr 嵌套 探究 Linux test tryme


在/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等命令。

标签:tmp,linuxprobe,27,Apr,嵌套,探究,Linux,test,tryme
来源: https://www.cnblogs.com/randyszone/p/16198255.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有