如何让 SELinux 在同一文件夹中允许 Apache 和 Samba?

Jos*_*eld 26 selinux centos samba apache-2.2

在我设置的配置中,我希望允许 samba 和 apache 访问 /var/www 我能够设置上下文以允许 samba 访问,但是 httpd 没有访问权限。使用 setenforce 到 0 可以消除问题,所以我知道它是 SELinux。

另外:如何查看文件夹的上下文,一个文件夹可以有多个上下文吗?

(CentOS)

Dav*_*vid 40

首先,您可以使用 ls -Z 查看带有 ls 的内容的上下文

[root@servername www]# ls -dZ /var/www
drwxr-xr-x  root root system_u:object_r:httpd_sys_content_t /var/www
Run Code Online (Sandbox Code Playgroud)

其次,有两个选项可以让 Samba 和 Apache 访问同一目录。

简单的方法是只允许 samba 读/写访问无处不在:

setsebool -P samba_export_all_rw 1
Run Code Online (Sandbox Code Playgroud)

它简单、容易,并且不会与 SELinux 的任何奇怪属性混淆。

如果您担心 Samba 拥有对所有目录的完全访问权限并且只想更改 /var/www,请尝试:

chcon -t public_content_rw_t /var/www
setsebool -P allow_smbd_anon_write 1
setsebool -P allow_httpd_anon_write 1
Run Code Online (Sandbox Code Playgroud)

这将允许 Samba 和 Apache 对具有 public_content_rw_t 上下文的任何目录进行写访问。请注意,chcon 仅修改 /var/www。在 /var/www 下创建的任何新目录都将是 public_content_rw_t,但不是像 /var/www/html 或 /var/www/manual 这样的现有目录。如果要更改所有内容,请在 chcon 中添加 -R:

chcon -R -t public_content_rw_t /var/www
Run Code Online (Sandbox Code Playgroud)

您可以浏览此 CentOS wiki 页面以获取有关其他 SELinux 布尔值的提示。

  • @Dave 你救了我的屁股。明天上班见。 (3认同)

小智 10

SHARING FILES
   If you want to share files with multiple domains (Apache,  FTP,  rsync,
   Samba),  you can set a file context of public_content_t and public_content_rw_t.
   These context allow any of the above domains  to  read  the
   content.   If  you want a particular domain to write to the public_con?
   tent_rw_t   domain,   you   must   set   the    appropriate    boolean.
   allow_DOMAIN_anon_write.  So for samba you would execute:

       setsebool -P allow_smbd_anon_write=1
Run Code Online (Sandbox Code Playgroud)

例如:

semanage fcontext -a -t public_content_rw_t '/var/www(/.*)?'
restorecon -R /var/www
setsebool -P allow_smbd_anon_write 1
Run Code Online (Sandbox Code Playgroud)