【问题标题】:(13)Permission denied: access to /~me denied(13)权限被拒绝:访问/~me被拒绝
【发布时间】:2014-08-10 16:49:20
【问题描述】:

我正在尝试配置 Apache httpd.conf(在我的 CentOS 6.4 上)以允许访问我的用户目录(即 ~me/public_html/index.html)。

我将原来的httpd.conf(即开箱即用)更改如下:

[root@myhost www]# diff /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.orig.out-of-the-box 
366c366
<     #UserDir disabled
---
>     UserDir disabled
373c373
<     UserDir public_html
---
>     #UserDir public_html

这原则上应该提供对http://myhost/~me 的访问权限,但相反,我得到了可怕的错误:

You don't have permission to access /~me on this server.

我检查了 /var/log/httpd/error_log 文件,果然,上面写着:

(13)Permission denied: access to /~me denied

我注意到的第一件奇怪的事情是/ 被添加到~me 前面。

  • 领先的/ 来自哪里?
  • 这只是“红鲱鱼”吗?
  • 或者这是否指向问题的根本原因(即我需要在 httpd.conf 中修改的其他内容)?

最重要的是,由于我知道我的~me/public_html 具有全球可读权限,我该如何解决此类问题?

有没有办法找出为什么“访问 /~me 被拒绝”?

  • SELinux?
  • httpd.conf?
  • 目录权限?
  • 以上所有?

更新 1,回答下面@UlrichSchwarz 在 cmets 中的 2 个问题:

  1. 主目录似乎确实有 'x' 权限:

    [root@myhost ~]# ls -lad /home/me

    drwxr-xr-x。 33 me me 4096 Feb 8 16:30 /home/me

  2. public_html 上的 SELinux 信息:

    [root@myhost ~]# ls -Z -d /home/me/public_html/

    drwxrwxr-x。我我 unconfined_u:object_r:file_t:s0 /home/me/public_html/


更新 2,在我确认这确实是一个 SELinux 问题之后(感谢 @Scolytus 的提示):

  1. 我运行了命令:

    chcon -R -t httpd_user_content_t /home/me/public_html/

    还是不行。

    [root@myhost ~]# ls -Z -d /home/me/public_html/

    drwxrwxr-x。我我 unconfined_u:object_r:httpd_user_content_t:s0 /home/me/public_html/

  2. 然后我运行“允许 HTTPD 读取主目录”from the command line

    setsebool -P httpd_enable_homedirs=1

    还是不行。

/var/log/httpd/error_log 现在显示(除了 (13)permission denied 错误)以下内容:

 [notice] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
 [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
 [notice] Digest: generating secret for digest authentication ...
 [notice] Digest: done
 [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations

也许问题在于 context_system_u 和 httpd_user_content_t 之间的差异?

我还需要做什么? (即没有完全禁用 SELinux)


更新 3,感谢@lserni 回答中的信息,我发现了ausearch 命令:

ausearch -m avc --start today

它提供了以下输出:

time->Fri Jul  4 09:16:44 2014
type=SYSCALL msg=audit(1404479804.256:1312): arch=40000003 syscall=196 success=no exit=-13 a0=12c2c80 a1=bfeb1d00 a2=a34ff4 a3=2008171 items=0 ppid=5880 pid=5886 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=193 comm="httpd" exe="/usr/sbin/httpd" subj=unconfined_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1404479804.256:1312): avc:  denied  { getattr } for  pid=5886 comm="httpd" path="/home/me" dev=dm-3 ino=2 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:file_t:s0 tclass=dir

嗯?为什么是/home/me 而不是/home/me/public_html

这是ls -Zd /home/me/的输出:

drwxr-xr-x. me me system_u:object_r:file_t:s0      /home/me/

我也应该在 /home/me 上运行 chcon -t httpd_user_content_t 吗?

继续研究...


更新 4:成功!

我运行了命令:

chcon -t httpd_user_content_t /home/me/

现在一切都很好。

[root@myhost sa]# ls -Z -d /home/me/

drwxr-xr-x. me me system_u:object_r:httpd_user_content_t:s0 /home/me/

【问题讨论】:

  • 服务器可能首先需要在您的主目录上使用+x,以查看您是否首先存在public_html,是这样吗?
  • 你能发布ls -Z -d public_html/的输出吗? (-Z 列出 SELinux 信息;这取自 the SELinux FAQ
  • 您可以尝试暂时禁用 SELinux,看看是否真的是问题所在。
  • 您可能想要检查/安装sealert/setroubleshootd 组合。它可以成为救生员。在我的 OpenSuSE 系统上,我可以在 /var/log "auditd" 日志文件中找到一些 SE 问题;你用的是什么发行版?
  • 当然。傻我:为了能够访问/home/me/public_html,Apache 需要有权读取/home/me 目录内容(即那里的文件和目录的名称 - 目录执行位)。见askubuntu.com/questions/26848/…

标签: apache httpd.conf


【解决方案1】:

我已经看到a slightly different version 提供的您给出的命令,由sealert 提供:

SELinux 拒绝访问 httpd 请求的 /var/www/html/file1。 /var/www/html/file1 有一个上下文用于不同的共享 程序。如果您想从 httpd 共享 /var/www/html/file1 此外,您需要将其文件上下文更改为 public_content_t。如果 您不打算进行此访问,这可能表示入侵 尝试。

允许访问:

您可以通过执行 chcon -t public_content_t 来更改文件上下文 '/var/www/html/file1'

修复命令:

chcon -t public_content_t '/var/www/html/file1'

如何解决此类问题?

大多数与 SELinux 相关的信息通常都在 auditd 日志中,但您可能需要一些工具(例如 sealert)来为您解码。我做了一个简短的搜索,并想出了这个我不知道但似乎很有趣的工具:SELinux GUI

附录Some examples with semanage

【讨论】:

  • @lsemi +1 尝试解开这个谜团。我运行了您的 chcon -t public_content_t 命令,但它也没有帮助。我怀疑问题与日志中关于 "httpd 作为上下文系统_u 运行" 的内容有关
  • 为了确定,在默认的 httpd DocumentRoot 上运行ls -lZ - Apache 能够读取的那个。之后,您可以使用 semanage/restorecon 将相同的上下文分配给 public_html 目录。另见:techrepublic.com/blog/linux-and-open-source/…
  • drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
  • 见鬼。然后semanage fcontext -a -t httpd_sys_content_t '/home/~me/public_html(/.*)?' &amp;&amp; restorecon -Rv ''/home/~me/public_html'必须工作。我没有可用于测试的 CentOS 64,但我可能会在这个星期天在虚拟机上试一试(目前还不能保证,抱歉)。
  • 以上内容并不完全正确。这是必要的,但还不够。也请参阅对该问题的评论。整个路径必须可供 Apache 搜索。
【解决方案2】:

我无法立即检查,但我记得注释掉 UserDir disabled 与启用不一样!

更具体地说,我认为您需要在 https.conf 文件中包含一行

Userdir enabled me

【讨论】:

  • 添加行 UserDir public_html 一切正常。我猜你不明白diff 的输出。
  • 此外,@Nick 的回答是在 我发布了我关于SELinux 问题 问题的调查结果。
  • 为了记录,当我发布我的报价时,SELinus 的东西不在那里。鉴于您的评论幼稚易怒,我怀疑我在您出生之前就使用了 diff (大约从 1981 年开始)。如果你一开始就对问题给出了详尽的描述(即承认使用 SELinux 而不仅仅是谈论权限),我就不会发布了。
猜你喜欢
  • 2018-07-19
  • 2014-03-24
  • 2017-11-03
  • 1970-01-01
  • 1970-01-01
  • 2018-06-11
  • 2018-11-10
  • 2017-04-20
  • 2011-06-11
相关资源
最近更新 更多