大网数据广告活动
服务器运维问答

CentOs 7 & SELInux: User cant write in the Webroot of Apache

· 52CE 我爱测

My user can't add, modify or delete apache/php files without sudo. My enviroment is: CentOS Linux release 7.2.1511 SELinux status: enabled Current mode: enforcing Apache 2.4.23 My user is already on the group of apache: $ id uid=…

问题原文

原帖链接 · Lenin Meza · CC BY-SA 3.0

My user can't add, modify or delete apache/php files without sudo.

My enviroment is:

  • CentOS Linux release 7.2.1511
  • SELinux status: enabled
  • Current mode: enforcing
  • Apache 2.4.23

My user is already on the group of apache:

$ id
uid=1000(lmeza) gid=1000(lmeza) groups=1000(lmeza),10(wheel),48(apache) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

The Webroot of Apache already have the label httpd_sys_content_t

$ ls -Z /var/www
drwxr-xr-x. root   root   system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin
drwxr-sr-x. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 html

I have a directory with the label httpd_sys_rw_content_t but i can't write on him:

$ ls -lahZ /var/www/html
drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 modules

$ touch /var/www/html/modules/abc.txt
touch: cannot touch ‘/var/www/html/modules/abc.txt’: Permission denied

Correct Get file access control lists:

$ getfacl /var/www/html
getfacl: Removing leading '/' from absolute path names
# file: var/www/html
# owner: apache
# group: apache
# flags: -s-
user::rwx
user:apache:rwx
group::r-x
group:apache:rwx
mask::rwx
other::r-x
default:user::rwx
default:user:apache:rwx
default:group::r-x
default:group:apache:rwx
default:mask::rwx
default:other::r-x

已采纳解答

原帖链接 · Lenin Meza · CC BY-SA 3.0

The correct way to establish SELinux and ACL permissions that work on CentOs 7 are:

# Restablish the SELInux context:
sudo restorecon -Rv /var/www/html
# Change the owner of the webroot:
sudo chown -R apache:apache /var/www/html
# Change basic permissiones:
sudo chmod -R g+w /var/www/html
sudo chmod g+s /var/www/html
# Establish SELinux permissions:
sudo chcon -Rt httpd_sys_content_t /var/www/html
sudo chcon -Rt httpd_sys_rw_content_t /var/www/html/modules
# Establish ACL permissions:
sudo setfacl -R -m u:apache:rwx /var/www/html
sudo setfacl -R -m d:u:apache:rwx /var/www/html
sudo setfacl -R -m g:apache:rwx /var/www/html
sudo setfacl -R -m d:g:apache:rwx /var/www/html

The full script for Drupal 8 is on the next Gist: https://gist.github.com/merolhack/854c3d371f31b21fb6cb538fe02a0444

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。