【问题标题】:Why can't HTTP process write into directory with group permissions?为什么 HTTP 进程不能写入具有组权限的目录?
【发布时间】:2017-08-20 18:26:38
【问题描述】:

我在 Amazon 实例和我的 Mac 上都遇到了问题。

我有两个用户

  • ec2-user:ec2-usermyuser:staff 用于 mac)
  • apache:ec2-user_www:staff 用于 mac)

.
如果我有一个由apache 创建的目录,ec2-user 可以在它下面完美写入

drwxrwsr-x 3 apache ec2-user 4.0K Mar 27 20:37 /path/to/sample/dir
// ec2-user can write here

但是在相反的情况下,如果ec2-user 是目录的所有者,当 apache 尝试在它下面写入时,它会抛出一个错误,说它没有足够的权限。

drwxrwsr-x 3 ec2-user ec2-user 4.0K Mar 27 20:37 /path/to/sample/dir
// apache CANNOT write here

但是如果我把权限改成777,那么`apache就可以在里面写了

drwxrwsrwx 3 ec2-user ec2-user 4.0K Mar 27 20:37 /path/to/sample/dir
// apache CAN write here
// file created would have `664 apache:ec2-user` permissions

所以问题是

为什么虽然两个用户有同一个组,但apache 不能写入一个明确对该组有写权限的目录?


附加
虽然apacheec2-user 为组写入,但当我执行以下操作时,我意识到apache 不属于ec2-user 组,那么它在写入时,它创建的文件和目录为什么会有这样的组?

sudo -u apache id
uid=48(apache) gid=48(apache) groups=48(apache)

【问题讨论】:

    标签: macos apache amazon-web-services amazon-ec2 permissions


    【解决方案1】:

    经过进一步研究并与一些系统管理员交谈后,答案直接进入了apache 所属的组。

    不管apache 的目录文件有ec2-user 组的因素,并不意味着apache 属于该组。

    所以,为了解决这个特定的请求,我所要做的就是将 Apache 添加到 ec2-user 组。

    sudo usermod -a -G ec2-user apache
    

    我还不太清楚mac版本,但它遵循使用dseditgroup命令的方式。

    【讨论】:

      猜你喜欢
      • 2010-10-08
      • 2021-06-21
      • 2023-03-15
      • 2011-06-30
      • 2011-04-29
      • 2015-11-07
      • 2019-08-03
      • 2015-10-04
      相关资源
      最近更新 更多