拥有文件的权限被拒绝

Bar*_*tak 1 linux permissions chmod

我在为特定用户设置权限时遇到问题。

我有一个目录/srv/git/,我试图在其中创建一个test 包含一个文件testfile(由 拥有www:www-data)的子目录。testfile应该只能由用户和组而不是其他人读写。

[root@bartplatak ~]# cd /srv/git
[root@bartplatak git]# mkdir test && touch test/testfile
[root@bartplatak git]# chown -R www:www-data test
[root@bartplatak git]# chmod o= test/testfile
[root@bartplatak git]# chmod -R ug=rw test
[root@bartplatak git]# sync
[root@bartplatak git]# su www
Run Code Online (Sandbox Code Playgroud)

但是由于某些未知原因,我无法cd进入目录(并且列出它显示的信息非常不完整)

bash-4.1$ pwd
/srv/git

bash-4.1$ ls -la test
ls: cannot access test/.: Permission denied
ls: cannot access test/testfile: Permission denied
ls: cannot access test/..: Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
-????????? ? ? ? ?            ? testfile

bash-4.1$ cd test
bash: cd: test: Permission denied
Run Code Online (Sandbox Code Playgroud)

让我感到奇怪的是,..尽管可以访问,但显示的信息不完整(drwxr-xr-x 6 root root 4096 Mar 1 19:02 .)。

编辑:我运行它的机器是带有CentOS release 6.5 (Final).

Linux bartplatak.com 2.6.32-042stab078.28 #1 SMP Mon Jul 8 10:17:22 MSK 2013 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

SELinux(据我所知)已禁用

[root@bartplatak ~]# sestatus 
SELinux status:                 disabled
Run Code Online (Sandbox Code Playgroud)

目录(和父目录)的权限设置为

drwxr-xr-x 6 root root     4096 Mar  1 19:02 /
drwxr-xr-x 5 root root     4096 Mar  1 14:16 /srv
drwxr-xr-x 6 root root     4096 Mar  1 19:02 /srv/git
drw-rw-r-x 2 www  www-data 4096 Mar  1 19:02 /srv/git/test
-rw-rw---- 1 www  www-data    0 Mar  1 19:02 /srv/git/test/testfile

[root@bartplatak git]# stat /srv/git/test
  File: `/srv/git/test'
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 5ae0b691h/1524676241d   Inode: 404068      Links: 2
Access: (0665/drw-rw-r-x)  Uid: (  497/     www)   Gid: (  496/www-data)


[root@bartplatak git]# stat /srv/git/test/testfile
  File: `/srv/git/test/testfile'
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 5ae0b691h/1524676241d   Inode: 404071      Links: 1
Access: (0660/-rw-rw----)  Uid: (  497/     www)   Gid: (  496/www-data)
Run Code Online (Sandbox Code Playgroud)

之后su wwwid显示uid=497(www) gid=497(www) groups=497(www),496(www-data)

Mic*_*ton 8

明显的问题是/srv/git/test没有x为所有者和组设置可执行位。因此不可能遍历目录

用以下方法解决问题:

chmod ug+x /srv/git/test
Run Code Online (Sandbox Code Playgroud)