Linux有两种用户:
- 超级用户:可以在Linux系统下做任何事情,不受限制
- 普通用户:可以在Linux系统下做有限的事情
- 超级用户的提示符是$ ,而普通用户的提示符是 #
要了解权限,我们从三个问题入手
1.始终权限问题
目录
在Linux系统中系统默认 目录权限:777, 普通文件:666
[root@zhangsan mytmp]# mkdir teset [root@zhangsan mytmp]# mkdir test [root@zhangsan mytmp]# ll total 0 drwxr-xr-x. 2 root root 6 Apr 4 19:10 teset #为什么目录权限是755 -rw-r--r--. 1 root root 0 Apr 4 19:14 test #为什么文件权限是644
其实这是指令 umask 在搞鬼
[root@zhangsan mytmp]# umask 0022 #这里的 umask 掩码值每台机子可能不一样 我的是0022
搞清楚 权限始终问题 后,我们开始下一个问题
2.目录权限:
想要观察 目录文件的权限 对其本身的影响时,需先进入
#观察哪一个权限能够影响是否进入目录 #'r'权限 [why@zhangsan share]$ chmod 444 test [why@zhangsan share]$ ll total 0 dr--r--r--. 2 why why 17 Apr 4 22:05 test #'w'权限 [why@zhangsan share]$ cd test -bash: cd: test: Permission denied [why@zhangsan share]$ chmod 222 test [why@zhangsan share]$ ll total 0 d-w--w--w-. 2 why why 17 Apr 4 22:05 test #'x'权限 [why@zhangsan share]$ cd test -bash: cd: test: Permission denied [why@zhangsan share]$ chmod 111 test [why@zhangsan share]$ ll total 0 d--x--x--x. 2 why why 17 Apr 4 22:05 test [why@zhangsan share]$ cd test [why@zhangsan test]$
总结:想要进入所创建目录文件,其必须包含权限 'x' ,'x'权限是必须的
观察 对目录文件内容进行增加、修改、删除
因为我们测试时权限不够,所以用root用户进行查看文件的修改
#对目录文件 内容 进行查看和修改 /* 普通用户 */ [why@zhangsan share]$ cd test [why@zhangsan test]$ ls -l ls: cannot open directory '.': Permission denied [why@zhangsan test]$ touch new [why@zhangsan test]$ mv new chese [why@zhangsan test]$ rm -rf chese
# 使用 root用户 观察命令的修改 [root@zhangsan share]# ls -l total 0 d-wx-wx-wx. 2 why why 6 Apr 4 22:37 test [root@zhangsan share]# cd test [root@zhangsan test]# ll total 0 -rw-r--r--. 1 why why 0 Apr 4 22:38 new [root@zhangsan test]# ll total 0 -rw-r--r--. 1 why why 0 Apr 4 22:38 chese [root@zhangsan test]# ll total 0 -rw-r--r--. 1 why why 0 Apr 4 22:38 chese [root@zhangsan test]# ll total 0
总结:修改目录文件内容需要 'w' 权限,还可以得出,想要查看指定目录的内容,需要目录的 'r'权限
搞清楚 目录文件权限 对应的作用后,我们继续下一个问题
3.粘滞位
有时候我们多个用户想要进行文件数据的共享,但是进行文件创建后,如果碰上不讲理的人删掉我们的文件,我们这时是没办法直接阻止其删掉我们的文件
不用怕,想要解决这个问题,只需要了解新的执行权限
-t(粘滞位) -- 一种特殊的执行权限
[root@zhangsan share]# chmod o+t test [root@zhangsan share]# ll total 0 d-wx-wx-wt. 2 why why 6 Apr 4 22:40 test
这样子修改后,其他人就只能对文件进行增加,修改,不能进行删除
w