我准备的部署推7网站上,我找不到任何文档中关于有什么建议安全意识的文件和目录的权限应定。

具体地说 default/files/ (也子目录?), settings.php, .htaccess 和什么我应该知道的。

有帮助吗?

解决方案

您的Web服务器应该能够读取所有文件,但是 不是 写信给他们。如果您的网站涉及上传文件,则将服务器许可仅写入该文件夹。

有关如何设置该设置的更多信息,以及如果您不这样做的某些事情可能会发生 Drupal文档.

其他提示

Drupal 页面像许多人一样很长,令人困惑。但它包含杰森(Jason)的这篇文章,后者击中了指甲:

Jason Sale发表于2010年11月1日下午12:40

感谢您写这篇文章和所有内容,但是我和99%的阅读此页面的人真正想要的是文件夹列表旁边的数字列表。

  • /default 在755上
  • /default/files 包括744(或755)上的所有子文件夹和文件
  • /default/themes 包括755的所有子文件夹和文件
  • /default/modules 包括755的所有子文件夹和文件
  • /default/settings.php/default/default.settings.php 在444上

我涉及在服务器上创建新的Drupal网站的练习是让一个用户是Web服务器(通常是Apache)组的一部分,并让该用户拥有所有Drupal文件。在Ubuntu上,这些是设置该设置的命令:

# Create a new example user, setting up /var/www/example as their home dir.
useradd -s /bin/bash -d /var/www/example -m example

# Now add that user to the Apache group. On Ubuntu/Debian this group is usually
# called www-data, on CentOS it's usually apache.
usermod -a -G www-data example

# Set up a password for this user.
passwd example

设置该设置后,我将登录该用户并在/var/www/example/docroot或类似的情况下安装drupal,然后手工创建文件目录,然后通过settings.php文件复制。由于我们在Drupal复制之前登录为示例用户,因此我们的文件所有权和权限应自动在所有核心Drupal文件和脚本(包括.htaccess文件)上正确配置。

su - example
cd docroot
cp sites/default/default.settings.php sites/default/settings.php

# Temporarily give the web server write permissions to settings.php
chgrp www-data sites/default/settings.php
chmod g+w sites/default/settings.php

现在,让我们设置文件目录。

# Create the directory.
mkdir sites/default/files

# Now set the group to the Apache group. -R means recursive, and -v means 
# verbose mode.
chgrp -Rv www-data sites/default/files

接下来,我们将设置权限,以便Web服务器始终写入此目录中的任何文件。我们通过在CHMOD命令中使用2775来做到这一点。 2表示将保留该目录中创建的任何新文件的组ID。这意味着www-data将始终是任何文件上的组,从而确保Web服务器和用户都将始终具有对该目录中放置的任何新文件的写入权限。第7个意味着所有者(示例)可以R(read)W(写)和X(执行)此处的任何文件。第二7个意味着组(www-data)也可以RW和x此目录中的任何文件。最后,这5个意味着其他用户可以R和X文件,但不能写入。

 chmod 2775 sites/default/files

如果此目录中有任何现有文件,请确保Web服务器上有写入perms。

 chmod g+w -R sites/default/files

现在,Drupal可以安装。完成后,是 非常 重要的是要回到settings.php并确保所有用户只有读取权限。

 chmod 444 sites/default/settings.php

而已!此设置可确保您避免使用该目录的用户或Web服务器无法在文件目录中编写/更改/删除文件的任何情况。

在推文件夹中的文件应该可写入该网络服务器。最安全的方法就是改组,并使其组可写的,这样的:

chgrp www-data sites/default/files
chmod g+w sites/default/files

文件上传文件夹在一边,最安全的是chmod644所有文件,755为目录。

这可能是完成这个样(当运行在推网文件夹, . 对于前路径):

find . -type f | xargs chmod 644
find . -type d | xargs chmod 755

记住,你将需要设置 chmod g+w 再次运行后,上述命令,因为这些将重置的chmod上的所有文件和文件夹。

对“ Chmod blah”或“ Chown X”的任何建议是毫无意义的:默认用户是什么:组在文件上以及网络服务器的用户和分组的运行方式。

其他人链接的Drupal文档在这个话题上相当不错,但另一个资源是 安全审查模块 这有助于确保您的一切都正确设置。

我将答复考虑的情况的文件被创建服务器上使用FTP,使用的凭证不同,从一下其是网络服务器运行(通常情况下,Apache运行为没有人/nobody).这意味着用户人拥有的文件手动创造了前运行的推installer(其中包括还本文件上载服务器,从推档案)不是使用该用户运行的网络服务器(无论是用户名或组的比赛).这种情况下也适用的情况下这些文件是使用SSH。

  • 的settings.php 文件必须写从推安装,但一旦安装完成建议,以使它只读(安装程序的建议,并推将定期检查,如果该文件是真的只读)。在该方案中,我描述的,该权限的这种文件至少应该644.
  • 。就文件(这是目前在至少两个地点)应有权644.用户是谁创造的文件仍然应该能够复盖该文件,在下一版的推附带了一个.就文件,该文件已经更新(它已经发生了一次,当它已加入线的文件,以避免安全问题)。它也可能设置的权限444,但在这种情况下,权限应该变回644当的文件需要更新。
  • 目录中包含该文件的通过创建的模块(的 default/files 目录)必须(用户分配到网站服务器的进程,其随后的用户分配到的PHP scripts上运行的网络服务器):
    • 可读
    • 可写的
    • 可穿越的(该模块必须能够到达 default/files/<directory-used-by-the-module>/<sub-directory-used-by-the-module>)

推荐的文件/目录权限:

  • Drupal Webroot应该是世界可读的(请参阅: updater.inc): 0755
  • 对于公共上传目录:0755或0775
  • 对于私人上传目录:0750或0770
  • 对于公开上传的文件:0644或0664
  • 对于私人上传文件:0640或0660
  • 对于上传目录中的.htaccess(请参阅: file_create_htaccess()):0444(默认)或0644
  • for settings.php仅读取所有(和其他机密文件):0440
  • 对于所有其他Web目录:0755
  • 对于所有其他Web文件:0644

推荐的文件/目录所有权:

  • 所有上传目录/文件的所有者都应将Apache用户设置为
  • 所有Web/sources目录/文件的所有者都应将其设置为非APACHE用户,
  • (选择)所有来源的组应设置为Apache组,

以下是控制新项目的默认DIR/文件权限的变量:

file_chmod_directory: 0775
file_chmod_file: 0664

这是一些用于修复权限的脚本: fix-permissions.sh


阅读更多:


这是我用来修复公共/私人目录上远程主机上的权限的脚本:

#!/bin/sh -e
# Script to correct public/private directory and files permissions.
[ -z "$1" ] && { echo Usage: $0 @remote.dst; exit 1; }

DST="$1" && shift
GET_HTTP_GROUP='ps axo user,group,comm | egrep "(apache|httpd)" | grep -v ^root | uniq | cut -d\  -f 1'

drush $* $DST ssh 'PUB=$(drush dd %files) && PRIV=$(drush dd %private) && AGROUP=$('"$GET_HTTP_GROUP"') && chgrp -vR $AGROUP $PUB $PRIV && chmod -vR u+rwX,g+rwX,o+rX $PUB $PRIV'

注意:上面的代码将尝试 检索Apache组 并将其设置为 GET_HTTP_GROUP 多变的。

此外壳脚本在此页面的底部找到: https://www.drupal.org/node/244924

我偶尔运行它,以确保正确设置我的权限。

#!/bin/bash
# Help menu
print_help() {
cat <<-HELP
This script is used to fix permissions of a Drupal installation
you need to provide the following arguments:
1) Path to your Drupal installation.
2) Username of the user that you want to give files/directories ownership.
3) HTTPD group name (defaults to www-data for Apache).
Usage: (sudo) bash ${0##*/} --drupal_path=PATH --drupal_user=USER --httpd_group=GROUP
Example: (sudo) bash ${0##*/} --drupal_path=/usr/local/apache2/htdocs --drupal_user=john --httpd_group=www-data
HELP
exit 0
}
if [ $(id -u) != 0 ]; then
  printf "**************************************\n"
  printf "* Error: You must run this with sudo. *\n"
  printf "**************************************\n"
  print_help
  exit 1
fi
drupal_path=${1%/}
drupal_user=${2}
httpd_group="${3:-www-data}"
# Parse Command Line Arguments
while [ $# -gt 0 ]; do
  case "$1" in
    --drupal_path=*)
      drupal_path="${1#*=}"
      ;;
    --drupal_user=*)
      drupal_user="${1#*=}"
      ;;
    --httpd_group=*)
      httpd_group="${1#*=}"
      ;;
    --help) print_help;;
    *)
      printf "***********************************************************\n"
      printf "* Error: Invalid argument, run --help for valid arguments. *\n"
      printf "***********************************************************\n"
      exit 1
  esac
  shift
done
if [ -z "${drupal_path}" ] || [ ! -d "${drupal_path}/sites" ] || [ ! -f "${drupal_path}/core/modules/system/system.module" ] && [ ! -f "${drupal_path}/modules/system/system.module" ]; then
  printf "*********************************************\n"
  printf "* Error: Please provide a valid Drupal path. *\n"
  printf "*********************************************\n"
  print_help
  exit 1
fi
if [ -z "${drupal_user}" ] || [[ $(id -un "${drupal_user}" 2> /dev/null) != "${drupal_user}" ]]; then
  printf "*************************************\n"
  printf "* Error: Please provide a valid user. *\n"
  printf "*************************************\n"
  print_help
  exit 1
fi
cd $drupal_path
printf "Changing ownership of all contents of "${drupal_path}":\n user => "${drupal_user}" \t group => "${httpd_group}"\n"
chown -R ${drupal_user}:${httpd_group} .
printf "Changing permissions of all directories inside "${drupal_path}" to "rwxr-x---"...\n"
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
printf "Changing permissions of all files inside "${drupal_path}" to "rw-r-----"...\n"
find . -type f -exec chmod u=rw,g=r,o= '{}' \;
printf "Changing permissions of "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n"
cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
printf "Changing permissions of all files inside all "files" directories in "${drupal_path}/sites" to "rw-rw----"...\n"
printf "Changing permissions of all directories inside all "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n"
for x in ./*/files; do
    find ${x} -type d -exec chmod ug=rwx,o= '{}' \;
    find ${x} -type f -exec chmod ug=rw,o= '{}' \;
done
echo "Done setting proper permissions on files and directories"
Copy the code above to a file, name it "fix-permissions.sh" and run it as follows:
sudo bash fix-permissions.sh --drupal_path=your/drupal/path --drupal_user=your_user_name

Note: The server group name is assumed "www-data", if it differs use the --httpd_group=GROUP argument.

另外,如果您正在运行FastCGI,则PHP将以用户运行,并且可以访问用户可以访问的所有文件,除非您故意尝试避免这种情况。

这帮助我解决了我的OSX许可问题。我在 https://www.drupal.org/node/244924#comment-3741738 由Protoprasm用户。我就像他在移民后遇到问题。

[root@localhost]cd /path_to_drupal_installation/sites
[root@localhost]find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
[root@localhost]find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chmod ug=rw,o= "$FILE"; done
[root@localhost]find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmod ug=rwx,o= "$DIR"; done

有一个叫做的模块 安全审查 哪个检查您的网站是否安全。我也发现了一个很好的 关联 设置站点权限。

许可以下: CC-BY-SA归因
scroll top