管理区域的目录写入权限
我有一个网站,有一个小的管理区域。管理区域需要写入目录,但不想向组或其他任何人授予对该目录的写入权限(出于安全原因)。如何将目录(和子目录)的所有者更改为运行用户?
I have a site, with a small admin area. The admin area needs to write to a directory, but dont want to give write access to that directory to the group or for anybody else (for security reasons). How can I change the owner of the directory (and subdirectories) to the runing user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就操作系统而言,您的 PHP 程序将使用固定的用户 ID 运行。操作系统不知道谁正在访问该网站。
您需要做的是向运行 PHP 的用户授予写入文件的权限,然后信任 PHP 代码仅代表它认为是管理员用户的用户进行操作。
在操作系统级别上您可以(并且应该)做的最好的事情就是锁定文件系统的其他部分,以便 PHP 中的错误不会导致任何人访问此管理区域之外的文件。
Your PHP program will run with a fixed user id as far as the operating system is concerned. The OS does not know who is accessing the website.
What you need to do is give permission to write files to the user that PHP is running under, and then trust the PHP code to only act on behalf of who it considers to be admin users.
The best you can (and should) do on the OS level is to lock down other parts of the filesystem, so that an error in the PHP cannot cause anyone to get to files outside of this admin area.
PHP 中不存在模拟这样的事情,因此您必须忍受一个操作系统用户执行所有操作,无论谁登录到您的站点(来宾/用户/管理员)。
There's no such thing as impersonation in PHP, so you'll have to live with one OS user performing all actions, whoever is logged in to your site (guest / user / admin).
我将解释我们如何在我们的安装中管理它。
我们有两个组 - “网站管理员”和“上传”。每个网络开发人员都是这两个群体的成员。 Apache 仅是“上传”组的成员。我们将掩码设置为 002,并在目录上设置了 +s 标志。
我们的目录权限如下所示:
这对我们来说非常有效。权限严格且一致。 PHP 创建的任何文件都属于“上传”,因此所有网站管理员都可以编辑。 apache 无法编辑网站管理员的任何其他内容。
I'll explain how we manage that on our installations.
We've got two groups - "webmasters" and "uploads". Every web developer is member of both group. Apache is member of "uploads" group only. We have a mask set to 002 and +s flag set on directories.
Our directory permissions look like this:
This have worked for us amazingly. Permissions are tight and consistent. Any files PHP will create will belong to "upload" and thus be editable by all web-masters. Any other content by web-masters won't be editable by apache.