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

在configuration我有设置我希望允许桑巴和Apache访问/ var / www我能够设置一个上下文来允许桑巴访问,但然后httpd没有访问权限。 使用setenforce来消除问题,所以我知道它是SELinux。

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

(CentOS的)

首先,您可以使用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 

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

简单的方法是在任何地方只允许samba读/写访问:

 setsebool -P samba_export_all_rw 1 

这很简单,容易,不会混淆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 

这将允许Samba和Apache写入任何具有public_content_rw_t上下文的目录。 请注意,chcon只是修改/ var / www。 在/ var / www下创build的任何新目录都将是public_content_rw_t,但不是像/ var / www / html或/ var / www / manual这样的现有目录。 如果你想改变一切,添加一个-R chcon:

 chcon -R -t public_content_rw_t /var/www 

你可以通过这个CentOS wiki页面来看看其他SELinux布尔值的提示。

 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 

例如:

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