dongsheng66783619 2013-10-06 01:02
浏览 90
已采纳

PHP - 通过SSH创建的目录上的权限被拒绝

Under linux, using php 5.3

If I use mkdir in a php script to create a folder, then I have full access on this folder to add files or create folder inside it.

If I then login on the server via ssh, create a second folder, chown(recursively or not) to the exact same user:group as the one created by the php mkdir(), and chmod it to the the same exact permissions as the first folder then trying to access this folder to add a file or create a new folder inside it will throw a permission denied.

Trying to chmod 777 does not work either. I cannot for the life of me figure out the difference between the two :

drwxr-xr-x.  2 amadeous psacln     4096  6 oct.  02:38 test
drwxr-xr-x.  2 amadeous psacln     4096  6 oct.  02:39 testtest

Any idea appreciated.

EDIT AFTER COMMENTS The apache user is running with the user amadeous in the group psacln. mkdir() does create the new directory with this user and group A exec("whoami") returns amadeous as well. But still no go.

EDIT 2 AFTER COMMENTS ABOUT SELINUX BY GUIDO ls -Z does give different results although I don't know what to make of it :

drwxr-xr-x. amateous psacln system_u:object_r:httpd_sys_rw_content_t:s0 test
drwxr-xr-x. amateous psacln unconfined_u:object_r:user_tmp_t:s0 testtest

How do I go about fixing this ?

Thanks

  • 写回答

1条回答 默认 最新

  • dqlm80253 2013-10-06 11:47
    关注

    The right labeling for files and directories accessible from the httpd apache processes is httpd_sys_content_t; while the files generated have user_tmp_t:

    ls -Z
    drwxr-xr-x. amateous psacln system_u:object_r:httpd_sys_rw_content_t:s0 test
    drwxr-xr-x. amateous psacln unconfined_u:object_r:user_tmp_t:s0 testtest
    

    To fix the labeling, run (more info):

    chcon -t httpd_sys_content_t <directory>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装