您的位置:首页 > 运维架构 > Linux

linux权限问题总结

2015-11-15 13:46 363 查看
在linux系统中,一切皆是文件,一切文件皆有权限

目录是一个特殊的文件,而目录记录的是此目录下所有文件和目录的权限

在linux系统中,权限分为r(可读)w(可写)x(可执行)

权限的是针对用户的owner(主)group(组)other(其它用户)

对于一个用户来说,没有任何一个用户是没有组的,在新建一个用户的时候,如果没有给此用户指定组,系统则自动以此用户名新建一个组。

[test1@localhost ~]$ mkdir 123  //新建一个目录
[test1@localhost ~]$ ll  //查看该目录的权限
总用量 4
drwxrwxr-x. 2 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ cd 123  //进入目录123下
[test1@localhost 123]$ mkdir 456  //新建一个目录456
[test1@localhost 123]$ ll  //查看目录456的权限
总用量 4
drwxrwxr-x. 2 test1 test1 4096 11月 15 09:39 456


[test1@localhost ~]$ chmod 400 123
[test1@localhost ~]$ ll
总用量 4
dr--------. 3 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ touch ./123/456/123.txt
touch: 无法创建"./123/456/123.txt": 权限不够
[test1@localhost ~]$ chmod 200 123
[test1@localhost ~]$ ll
总用量 4
d-w-------. 3 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ touch ./123/456/123.txt
touch: 无法创建"./123/456/123.txt": 权限不够
[test1@localhost ~]$ chmod 100 123
[test1@localhost ~]$ ll
总用量 4
d--x------. 3 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ touch ./123/456/123.txt
[test1@localhost ~]$ ll ./123/456
总用量 0
-rw-rw-r--. 1 test1 test1 0 11月 15 10:56 123.txt
[test1@localhost ~]$ chmod 600 123
[test1@localhost ~]$ ll
总用量 4
drw-------. 3 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ touch ./123/456/123.txt
touch: 无法创建"./123/456/123.txt": 权限不够
[test1@localhost ~]$ chmod 300 123
[test1@localhost ~]$ ll
总用量 4
d-wx------. 3 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ touch ./123/456/123.txt
[test1@localhost ~]$ ll ./123/456
总用量 0
-rw-rw-r--. 1 test1 test1 0 11月 15 11:20 123.txt
[test1@localhost ~]$ chmod 500 123
[test1@localhost ~]$ ll
总用量 4
dr-x------. 3 test1 test1 4096 11月 15 09:39 123
[test1@localhost ~]$ touch ./123/456/123.txt
[test1@localhost ~]$ ll ./123/456
总用量 0
-rw-rw-r--. 1 test1 test1 0 11月 15 11:21 123.txt


通过以上的实验可以得出结论:在目录456拥有rwx权限的时候,目录123只有在拥有r-x,-wx,–x权限的时候,才可以在目录456下新建、查看文件或目录。

在将目录123的权限设置成–x,目录456的权限设置成–x,则无法查看目录123、456下的任何内容,也无法在目录123下新建文件,但是却可以在目录456下新建文件.

示例:

[test1@localhost ~]$ chmod 100 123
[test1@localhost ~]$ chmod 100 ./123/456
[test1@localhost ~]$ ll ./123/456
ls: 无法打开目录./123/456: 权限不够
[test1@localhost ~]$ touch ./123/123.txt
touch: 无法创建"./123/123.txt": 权限不够
[test1@localhost ~]$ touch ./123/456/123.txt
[test1@localhost ~]$ cd 123
[test1@localhost 123]$ ll
ls: 无法打开目录.: 权限不够
[test1@localhost 123]$ cd 456
[test1@localhost 456]$ cd ..
[test1@localhost 123]$ cd ..
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux