gpt4 book ai didi

php - 如何使用 semanage 递归地获取持久化特定文件类型

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:50 24 4
gpt4 key购买 nike

我目前正在运行 Centos 7 并配置启用了 SELinux,目前我在/home/user/public_html 下配置我的 apache docroot,文件/文件夹显示上下文标签:

-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 readme.html
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-activate.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-admin
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-blog-header.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-comments-post.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-config-sample.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-content
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-cron.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-includes
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-links-opml.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-load.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-login.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-mail.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-settings.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-signup.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-trackback.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 xmlrpc.php

我想递归地将当前上下文标签 httpd_user_content_t 分配和更改为 httpd_user_script_exec_t 并且仅适用于 public_html/下的所有 .php 文件类型。我已经尝试了下面的代码,但上下文仍然没有改变:

# sudo semanage fcontext -a -t httpd_user_script_exec_t "/home/user/public_html/.*\.php"
# sudo restorecon -Rv public_html
# ls -Z
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 readme.html
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-activate.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-admin
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-blog-header.php

最佳答案

我认为您缺少告诉 SELinux 您想要使用正则表达式的方括号。试试看:

sudo semanage fcontext -a -t httpd_user_script_exec_t "/home/user/public_html/(.*\.php)"

关于php - 如何使用 semanage 递归地获取持久化特定文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48608638/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com