Linux嵌套目录权限的比较探究
2022/4/28 7:14:28
本文主要是介绍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等命令。
这篇关于Linux嵌套目录权限的比较探究的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30[译]漫画SELinux概念
- 2024-03-29linux 移动文件
- 2024-03-28linux .so file
- 2024-03-28Linux 磁盘管理
- 2024-03-28Linux学习笔记(十三)磁盘管理(一):磁盘分区
- 2024-03-26linux 创建 文件
- 2024-03-25使用SecureCRT对Linux vim进行颜色设置
- 2024-03-202019-2020-12 20199317 《Linux内核原理与分析》 第十二周作业
- 2024-03-20Linux运维的第二周总结
- 2024-03-13how to count number of directories in linux