父目录的权限对子目录有没有影响?[Linux]

问题源头:

  登录到服务器(实验室分的一个服务器账号)上,想在当前目录下创建一个文件,但提示“文件系统只读”,无法创建文件。通过ls -l查看当前用户在当前目录的权限,发现具有rwx权限。所以在想会不会是因为我在父目录中没有w权限导致我无法在当前目录创建文件。但发现在父目录中我也是rwx权限...(最后,我感觉这个问题可能是服务器管理员对硬盘加了写保护) 

  于是我做了以下的实验,想验证"父目录的权限对子目录的权限有没有影响?"  例如,某用户在父目录(testDir)没有写权限,那么该用户在当前目录(testDir/abc/)能否执行写操作?

lxw ~$ ls -ld testDir/
drwxrwxr-x 3 lxw lxw 4096 Dec 26 09:10 testDir/
lxw ~$ chmod 500 testDir/
lxw ~$ ls -ld testDir/
dr-x------ 3 lxw lxw 4096 Dec 26 09:10 testDir/
lxw ~$ cd testDir/
lxw testDir$ touch parentFile  #合理,对testDir无w权限
touch: cannot touch ‘parentFile’: Permission denied
lxw testDir$ ls -l
total 8
drwxrwxr-x 2 lxw lxw 4096 Dec 26 10:07 abc
-rw-rw-r-- 1 lxw lxw    4 Dec 26 09:10 txt
lxw testDir$ cd abc/
lxw abc$ ls
lxw abc$ touch childFile     #父目录虽然没有w权限,但只要我能够进入当前目录(具有x权限),我就能够按照我在当前目录的权限,进行操作。
lxw abc$ ls
childFile

  所以,经过上面的验证,父目录虽然没有w权限,但只要我能够进入当前目录(具有x权限),我就能够按照我在当前目录的权限,进行读写操作。

  现在我让testDir/目录只保留x权限:

lxw ~$ chmod 100 testDir/
lxw ~$ ll -d testDir/
d--x------ 3 lxw lxw 4096 Dec 26 09:10 testDir//
lxw ~$ cd testDir/
lxw testDir$ ls       #合理, 没有r权限
ls: cannot open directory .: Permission denied
lxw testDir$ ll -d abc   #虽然我在testDir/没有r权限,无法看其有哪些文件,但若我事先已知道它有哪些文件,我就可以通过ls对这些文件进行查看。
drwxrwxr-x 2 lxw lxw 4096 Dec 26 10:25 abc/
lxw testDir$ ll txt       #同上
-rw-rw-r-- 1 lxw lxw 4 Dec 26 09:10 txt
lxw testDir$ touch a     #合理, 没有w权限
touch: cannot touch ‘a’: Permission denied
lxw testDir$ cd abc
lxw abc$ ls
childFile
lxw abc$ ll -ld .
drwxrwxr-x 2 lxw lxw 4096 Dec 26 10:13 ./
lxw abc$ touch childFile2  #虽然我在父目录中没有rw权限,但只要我能进入该目录(x权限),我就可以按照我在当前目录中的权限进行操作。
lxw abc$ ls -l
total 0
-rw-rw-r-- 1 lxw lxw 0 Dec 26 10:13 childFile
-rw-rw-r-- 1 lxw lxw 0 Dec 26 10:25 childFile2

  所以,通过上面的实验,我认为,只要父目录具有x权限,父目录的权限和子目录的权限没有直接的关系,不会相互影响

  最后,通过下面的例子进一步说明:

lxw ~$ chmod 600 testDir/
lxw ~$ ls -ld testDir/
drw------- 3 lxw lxw 4096 Dec 26 09:10 testDir/
lxw ~$ cd testDir/    #合理,没有x权限
bash: cd: testDir/: Permission denied
lxw ~$ ls -l testDir/   #有r权限
ls: cannot access testDir/txt: Permission denied
ls: cannot access testDir/abc: Permission denied
total 0
d????????? ? ? ? ?            ? abc
-????????? ? ? ? ?            ? txt
lxw ~$ cd testDir/abc
bash: cd: testDir/abc: Permission denied

  最后一条语句, 我对abc目录具有rwx权限,对testDir具有rw权限,但我无法进入testDir/abc(父目录的权限影响到了子目录的权限),原因正是我对testDir没有x权限。

  如果您有不同的观点,欢迎您与我交流。

 

posted @ 2014-12-26 11:02  XiaoweiLiu  阅读(10875)  评论(0编辑  收藏  举报