Unix上的文件系统权限

如果我有一个指定为不可读的文件夹。 它下面的所有文件夹也是不可读的? 例如,我的共享主机主目录目录不能被其他帐户访问,所以,那个主目录目录下的0777文件夹和文件也是不可访问的?

目录有两个不同的读取权限。 您拥有标准的读取权限,就像使用文件一样。 这会阻止你在目录上执行opendir()/ readdir()。 这基本上阻止你在目录中做一个ls。 如果你知道它们的名字,你仍然可以访问子目录。 你也有执行权限,在目录的情况下,你不能访问里面的文件。 您不能将目录更改为您没有执行权限的目录,并且无法访问其下的任何内容,但仍然可以读取内容。

# mkdir -p read/subdirectory # mkdir -p execute/subdirectory # chmod ox execute/ # chmod or read # logout % ls -ld read/ execute/ drwxr-xr-- 3 root root 4096 2009-10-20 14:43 execute/ drwxr-x--x 3 root root 4096 2009-10-20 14:43 read/ % ls read ls: cannot open directory read: Permission denied % ls execute ls: cannot access execute/subdirectory: Permission denied subdirectory % cd read/subdirectory % cd - % cd execute/subdirectory bash: cd: execute/subdirectory: Permission denied 

你会注意到, ls execute显示一个错误和子目录。 原因是ls被允许读取执行目录并发现子目录,但是ls会对这个子目录进行统计,并在那里得到一个拒绝的权限。

答案是“是”。 例如,如果/ foo是模式-rx------ ,除了所有者以外,没有人可以读取或更改为/ foo,因此无论权限如何,该目录下的所有内容对其他人都是不可访问的。

这取决于实现,但是在大多数现代unix中阻止访问父文件夹也将阻止访问子文件夹,无论其个人权限如何。

 user@host:/$ sudo chmod 700 test user@host:/$ sudo ls -ld test/test drwxr-xr-x 2 root root 4096 2009-10-20 15:29 test/test user@host:/$ ls -ld test/test ls: cannot access test/test: Permission denied 

如果你想授予子文件夹的访问权限,你可以在父文件夹上设置执行位。

 user@host:/$ sudo chmod 711 test user@host:/$ ls -l test ls: cannot open directory /test: Permission denied user@host:/$ ls -ld test/test drwxr-xr-x 2 root root 4096 2009-10-20 15:29 test/test 

正如你所看到的,这可以防止父文件夹的列表,但允许访问子文件夹和文件。

可以阅读父目录不可读的目录:

 [kbrandt@kb: ~/scrap/perm] ls -ld foo d--x------ 4 kbrandt kbrandt 4096 2009-10-20 08:45 foo [kbrandt@kb: ~/scrap/perm] ls -ld foo/bar drwxrwxr-x 3 kbrandt kbrandt 4096 2009-10-20 08:55 foo/bar [kbrandt@kb: ~/scrap/perm] ls foo ls: cannot open directory foo: Permission denied [kbrandt@kb: ~/scrap/perm] ls foo/bar baz foo 

目录权限不是你所想的(从我的post中收集到的):

执行(search) – 进入目录
写入 – 在该目录中创build和删除文件
读取 – 列出目录中的文件

执行(search)确实要求所有的父母都执行设置,不像读写。

这是为什么理解目录权限很重要的一个例子:
即使root拥有一个文件,并且没有其他用户拥有对该文件本身的写入权限,如果其他用户可以写入并search到该目录,那么该用户可以删除该文件(假设这是最后剩下的硬链接)。