免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: jeanlove
打印 上一主题 下一主题

[一个讨论]"文件权限"的作用范围,是否只限于本机? 悖论 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-09-11 15:49 |只看该作者
顺便延伸下:
关于文件是否能在linux或unix下删除取决于它的上级目录还是它的自身其他组的权限

我上虚拟机做了个试验。AS4环境
测试默认目录权限下:
root用户建立文件
  1. [root@test home]# mkdir abc
  2. [root@test home]# cd abc
  3. [root@test abc]# touch test0
  4. [root@test abc]# chmod 700 test0
  5. [root@test abc]# touch test1
  6. [root@test abc]# chmod 701 test1
  7. [root@test abc]# touch test2
  8. [root@test abc]# chown 702 test2
  9. [root@test abc]# touch test2
  10. [root@test abc]# chmod 702 test2
  11. [root@test abc]# touch test3
  12. [root@test abc]# chmod 703 test3
  13. [root@test abc]# touch test4
  14. [root@test abc]# chmod 704 test4
  15. [root@test abc]# touch test5
  16. [root@test abc]# chmod 705 test5
  17. [root@test abc]# touch test6
  18. [root@test abc]# chmod 706 test6
  19. [root@test abc]# touch test7
  20. [root@test abc]# chmod 707 test7
  21. [root@test abc]# ls -al
  22. total 48
  23. drwxr-xr-x  2 root root 4096 Apr 13 19:28 .
  24. drwxr-xr-x  9 root root 4096 Apr 13 19:25 ..
  25. -rwx------  1 root root    0 Apr 13 19:32 test0
  26. -rwx-----x  1 root root    0 Apr 13 19:26 test1
  27. -rwx----w-  1 root root    0 Apr 13 19:26 test2
  28. -rwx----wx  1 root root    0 Apr 13 19:26 test3
  29. -rwx---r--  1 root root    0 Apr 13 19:26 test4
  30. -rwx---r-x  1 root root    0 Apr 13 19:27 test5
  31. -rwx---rw-  1 root root    0 Apr 13 19:27 test6
  32. -rwx---rwx  1 root root    0 Apr 13 19:27 test7

复制代码


test用户测试
  1. [test@test home]$ cd /home/abc/
  2. [test@test abc]$ id
  3. uid=503(test) gid=503(test) groups=503(test) context=user_u:system_r:unconfined_t
  4. [test@test abc]$ ls -al
  5. total 48
  6. drwxr-xr-x  2 root root 4096 Apr 13 19:34 .
  7. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  8. -rwx------  1 root root    0 Apr 13 19:34 test0
  9. -rwx-----x  1 root root    0 Apr 13 19:34 test1
  10. -rwx----w-  1  702 root    0 Apr 13 19:34 test2
  11. -rwx----wx  1 root root    0 Apr 13 19:34 test3
  12. -rwx---r--  1 root root    0 Apr 13 19:34 test4
  13. -rwx---r-x  1 root root    0 Apr 13 19:34 test5
  14. -rwx---rw-  1 root root    0 Apr 13 19:34 test6
  15. -rwx---rwx  1 root root    0 Apr 13 19:34 test7
  16. [test@test abc]$ rm *
  17. rm: remove write-protected regular empty file `test0'? y
  18. rm: cannot remove `test0': Permission denied
  19. rm: remove write-protected regular empty file `test1'? y
  20. rm: cannot remove `test1': Permission denied
  21. rm: cannot remove `test2': Permission denied
  22. rm: cannot remove `test3': Permission denied
  23. rm: remove write-protected regular empty file `test4'? y
  24. rm: cannot remove `test4': Permission denied
  25. rm: remove write-protected regular empty file `test5'? y
  26. rm: cannot remove `test5': Permission denied
  27. rm: cannot remove `test6': Permission denied
  28. rm: cannot remove `test7': Permission denied
  29. [test@test abc]$ ls -al
  30. total 48
  31. drwxr-xr-x  2 root root 4096 Apr 13 19:34 .
  32. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  33. -rwx------  1 root root    0 Apr 13 19:34 test0
  34. -rwx-----x  1 root root    0 Apr 13 19:34 test1
  35. -rwx----w-  1  702 root    0 Apr 13 19:34 test2
  36. -rwx----wx  1 root root    0 Apr 13 19:34 test3
  37. -rwx---r--  1 root root    0 Apr 13 19:34 test4
  38. -rwx---r-x  1 root root    0 Apr 13 19:34 test5
  39. -rwx---rw-  1 root root    0 Apr 13 19:34 test6
  40. -rwx---rwx  1 root root    0 Apr 13 19:34 test7
复制代码


好修正abc目录权限
加上写的权限

  1. [root@test abc]# chmod 757 /home/abc
  2. [root@test abc]# ls -al
  3. total 48
  4. drwxr-xrwx  2 root root 4096 Apr 13 19:36 .
  5. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  6. -rwx------  1 root root    0 Apr 13 19:36 test0
  7. -rwx-----x  1 root root    0 Apr 13 19:36 test1
  8. -rwx----w-  1  702 root    0 Apr 13 19:36 test2
  9. -rwx----wx  1 root root    0 Apr 13 19:36 test3
  10. -rwx---r--  1 root root    0 Apr 13 19:36 test4
  11. -rwx---r-x  1 root root    0 Apr 13 19:36 test5
  12. -rwx---rw-  1 root root    0 Apr 13 19:36 test6
  13. -rwx---rwx  1 root root    0 Apr 13 19:36 test7
复制代码



test用户继续测试

  1. [test@test abc]$ ls -al
  2. total 48
  3. drwxr-xrwx  2 root root 4096 Apr 13 19:36 .
  4. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  5. -rwx------  1 root root    0 Apr 13 19:36 test0
  6. -rwx-----x  1 root root    0 Apr 13 19:36 test1
  7. -rwx----w-  1  702 root    0 Apr 13 19:36 test2
  8. -rwx----wx  1 root root    0 Apr 13 19:36 test3
  9. -rwx---r--  1 root root    0 Apr 13 19:36 test4
  10. -rwx---r-x  1 root root    0 Apr 13 19:36 test5
  11. -rwx---rw-  1 root root    0 Apr 13 19:36 test6
  12. -rwx---rwx  1 root root    0 Apr 13 19:36 test7
  13. [test@test abc]$ rm *
  14. rm: remove write-protected regular empty file `test0'? y
  15. rm: remove write-protected regular empty file `test1'? y
  16. rm: remove write-protected regular empty file `test4'? y
  17. rm: remove write-protected regular empty file `test5'? y
  18. [test@test abc]$ ls -al
  19. total 16
  20. drwxr-xrwx  2 root root 4096 Apr 13 19:36 .
  21. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
复制代码


目录其他组的7权限OK。
修改为3权限添加测试。
  1. [root@test abc]# chmod 753 /home/abc
  2. [root@test abc]# touch test0
  3. [root@test abc]# chmod 700 test0
  4. [root@test abc]# touch test1
  5. [root@test abc]# chmod 701 test1
  6. [root@test abc]# touch test2
  7. [root@test abc]# chown 702 test2
  8. [root@test abc]# touch test2
  9. [root@test abc]# chmod 702 test2
  10. [root@test abc]# touch test3
  11. [root@test abc]# chmod 703 test3
  12. [root@test abc]# touch test4
  13. [root@test abc]# chmod 704 test4
  14. [root@test abc]# touch test5
  15. [root@test abc]# chmod 705 test5
  16. [root@test abc]# touch test6
  17. [root@test abc]# chmod 706 test6
  18. [root@test abc]# touch test7
  19. [root@test abc]# chmod 707 test7
  20. [root@test abc]# ls -al
  21. total 48
  22. drwxr-x-wx  2 root root 4096 Apr 13 19:37 .
  23. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  24. -rwx------  1 root root    0 Apr 13 19:37 test0
  25. -rwx-----x  1 root root    0 Apr 13 19:37 test1
  26. -rwx----w-  1  702 root    0 Apr 13 19:37 test2
  27. -rwx----wx  1 root root    0 Apr 13 19:37 test3
  28. -rwx---r--  1 root root    0 Apr 13 19:37 test4
  29. -rwx---r-x  1 root root    0 Apr 13 19:37 test5
  30. -rwx---rw-  1 root root    0 Apr 13 19:37 test6
  31. -rwx---rwx  1 root root    0 Apr 13 19:37 test7
复制代码


test用户继续测试
没读的权限自然看不见文件。
  1. [test@test abc]$ ls -al
  2. ls: .: Permission denied
  3. [test@test abc]$ rm *
  4. rm: cannot remove `*': No such file or directory
  5. [test@test abc]$ rm test0
  6. rm: remove write-protected regular empty file `test0'? y
  7. [test@test abc]$ rm test1
  8. rm: remove write-protected regular empty file `test1'? y
  9. [test@test abc]$ rm test2
  10. [test@test abc]$ rm test3
  11. [test@test abc]$ rm test4
  12. rm: remove write-protected regular empty file `test4'? y
  13. [test@test abc]$ rm test5
  14. rm: remove write-protected regular empty file `test5'? y
  15. [test@test abc]$ rm test6
  16. [test@test abc]$ rm test7
复制代码


再到root终端看下
[root@test abc]# ls -al
total 16
drwxr-x-wx  2 root root 4096 Apr 13 19:37 .
drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..



再来个只有写的(2)权限看看

  1. [root@test abc]# chmod 702 /home/abc
  2. [root@test abc]# ls -al
  3. total 48
  4. drwx----w-  2 root root 4096 Apr 13 19:40 .
  5. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  6. -rwx------  1 root root    0 Apr 13 19:40 test0
  7. -rwx-----x  1 root root    0 Apr 13 19:40 test1
  8. -rwx----w-  1  702 root    0 Apr 13 19:40 test2
  9. -rwx----wx  1 root root    0 Apr 13 19:40 test3
  10. -rwx---r--  1 root root    0 Apr 13 19:40 test4
  11. -rwx---r-x  1 root root    0 Apr 13 19:40 test5
  12. -rwx---rw-  1 root root    0 Apr 13 19:40 test6
  13. -rwx---rwx  1 root root    0 Apr 13 19:40 test7
复制代码


test用户继续

[test@test abc]$ ls -al
ls: .: Permission denied
[test@test abc]$ rm test7
rm: cannot remove `test7': Permission denied
[test@test abc]$ ls -al
ls: .: Permission denied
[test@test abc]$ rm test0
rm: cannot remove `test0': Permission denied
[test@test abc]$ rm test1
rm: cannot remove `test1': Permission denied
[test@test abc]$ rm test2
rm: cannot remove `test2': Permission denied
[test@test abc]$ rm test3
rm: cannot remove `test3': Permission denied
[test@test abc]$ rm test4
rm: cannot remove `test4': Permission denied
[test@test abc]$ rm test5
rm: cannot remove `test5': Permission denied
[test@test abc]$ rm test6
rm: cannot remove `test6': Permission denied
[test@test abc]$ rm test7
rm: cannot remove `test7': Permission denied


那来个只有执行(1)权限的看看

  1. [root@test abc]# chmod 701 /home/abc
  2. [root@test abc]# ls -al
  3. total 48
  4. drwx-----x  2 root root 4096 Apr 13 19:40 .
  5. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  6. -rwx------  1 root root    0 Apr 13 19:40 test0
  7. -rwx-----x  1 root root    0 Apr 13 19:40 test1
  8. -rwx----w-  1  702 root    0 Apr 13 19:40 test2
  9. -rwx----wx  1 root root    0 Apr 13 19:40 test3
  10. -rwx---r--  1 root root    0 Apr 13 19:40 test4
  11. -rwx---r-x  1 root root    0 Apr 13 19:40 test5
  12. -rwx---rw-  1 root root    0 Apr 13 19:40 test6
  13. -rwx---rwx  1 root root    0 Apr 13 19:40 test7
复制代码


好看这次test用户如何

  1. [test@test abc]$ ls -al
  2. ls: .: Permission denied
  3. [test@test abc]$ rm test0
  4. rm: remove write-protected regular empty file `test0'? y
  5. rm: cannot remove `test0': Permission denied
  6. [test@test abc]$ rm test1
  7. rm: remove write-protected regular empty file `test1'? y
  8. rm: cannot remove `test1': Permission denied
  9. [test@test abc]$ rm test2
  10. rm: cannot remove `test2': Permission denied
  11. [test@test abc]$ rm test3
  12. rm: cannot remove `test3': Permission denied
  13. [test@test abc]$ rm test4
  14. rm: remove write-protected regular empty file `test4'? y
  15. rm: cannot remove `test4': Permission denied
  16. [test@test abc]$ rm test5
  17. rm: remove write-protected regular empty file `test5'? y
  18. rm: cannot remove `test5': Permission denied
  19. [test@test abc]$ rm test6
  20. rm: cannot remove `test6': Permission denied
  21. [test@test abc]$ rm test7
  22. rm: cannot remove `test7': Permission denied
  23. [test@test abc]$ ls -al
  24. ls: .: Permission denied
复制代码


再到root下看看?
  1. [root@test abc]# ls -al
  2. total 48
  3. drwx-----x  2 root root 4096 Apr 13 19:40 .
  4. drwxr-xr-x  9 root root 4096 Apr 13 19:34 ..
  5. -rwx------  1 root root    0 Apr 13 19:40 test0
  6. -rwx-----x  1 root root    0 Apr 13 19:40 test1
  7. -rwx----w-  1  702 root    0 Apr 13 19:40 test2
  8. -rwx----wx  1 root root    0 Apr 13 19:40 test3
  9. -rwx---r--  1 root root    0 Apr 13 19:40 test4
  10. -rwx---r-x  1 root root    0 Apr 13 19:40 test5
  11. -rwx---rw-  1 root root    0 Apr 13 19:40 test6
  12. -rwx---rwx  1 root root    0 Apr 13 19:40 test7
复制代码


其他的权限大家可以自己测试看看哦
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP