我在这里看了一下,但没有找到关于最佳文件权限的任何细节。我也在这里看了一些WordPress表单的问题,但任何建议777的人显然需要上一节安全课。

总之,我的问题是这样的。我应该拥有以下权限:

存储所有WordPress内容的根文件夹 wp-admin wp-content wp-includes

那每个文件夹里的所有文件呢?


当前回答

将所有wp文件的完全访问权限授予www-data用户(在这种情况下是web服务器用户)可能是危险的。 所以最好不要这样做:

chown www-data:www-data -R *

然而,当你安装或升级WordPress及其插件时,它会很有用。但是当你完成后,让web服务器拥有wp文件就不再是一个好主意了。

它基本上允许网络服务器在你的网站上放置或覆盖任何文件。 这意味着如果有人设法使用web服务器(或一些.php脚本中的安全漏洞)在您的网站中放置一些文件,就有可能接管您的网站。

为了保护您的网站免受此类攻击,您应该采取以下措施:

All files should be owned by your user account, and should be writable by you. Any file that needs write access from WordPress should be writable by the web server, if your hosting set up requires it, that may mean those files need to be group-owned by the user account used by the web server process. / The root WordPress directory: all files should be writable only by your user account, except .htaccess if you want WordPress to automatically generate rewrite rules for you. /wp-admin/ The WordPress administration area: all files should be writable only by your user account. /wp-includes/ The bulk of WordPress application logic: all files should be writable only by your user account. /wp-content/ User-supplied content: intended to be writable by your user account and the web server process. Within /wp-content/ you will find: /wp-content/themes/ Theme files. If you want to use the built-in theme editor, all files need to be writable by the web server process. If you do not want to use the built-in theme editor, all files can be writable only by your user account. /wp-content/plugins/ Plugin files: all files should be writable only by your user account. Other directories that may be present with /wp-content/ should be documented by whichever plugin or theme requires them. Permissions may vary.

来源及其他信息:http://codex.wordpress.org/Hardening_WordPress

其他回答

为了确保您的网站是安全的,并且您为文件夹使用了正确的权限,请使用如下安全插件:

https://en-ca.wordpress.org/plugins/all-in-one-wp-security-and-firewall/

https://en-ca.wordpress.org/plugins/wordfence/

这些插件会扫描你的Wordpress安装,并通知你任何潜在的问题。这些还将警告您任何不安全的文件夹权限。除此之外,这些插件会建议你应该给文件夹分配什么权限。

根据我在自己网站上的阅读和痛苦,在被黑客入侵后,我想出了上面的列表,其中包括一个名为Wordfence的Wordpress安全插件的权限。(非附属机构)

在我们的例子中,wordpress文档根是 /var/www/html/example.com/public_html

打开权限,以便www-data可以像下面这样写入文档根目录:

cd /var/www/html/example.com
sudo chown -R www-data:www-data public_html/

现在,作为管理员,您可以在站点的仪表板上执行更新。

按照以下步骤完成更新后的安全站点:

sudo chown -R wp-user:wp-user public_html/

上面的命令将wordpress安装中的所有内容的权限更改为wordpress FTP用户。

cd public_html/wp-content
sudo chown -R www-data:wp-user wflogs
sudo chown -R www-data:wp-user uploads

上面的命令确保安全插件Wordfence可以访问它的日志。上传目录也可以通过www-data写入。

cd plugins
sudo chown -R www-data:wp-user wordfence/

上面的命令还确保安全插件为其正确的功能需要读写访问。

目录和文件权限

# Set all directories permissions to 755
find . -type d -exec chmod 755 {} \;

# Set all files permissions to 644
find . -type f -exec chmod 644 {} \;

将wp-config.php的权限设置为640,这样只有wp-user可以读取该文件,其他用户不能读取。440的权限不适合我以上的文件所有权。

sudo chmod 640 wp-config.php

使用SSH的Wordpress自动更新在PHP5上运行正常,但在PHP7.0上就不行了,因为PHP7.0 -ssh2与Ubuntu 16.04绑定的问题,我不知道如何安装正确的版本并使其工作。幸运的是,一个非常可靠的插件ssh- SFTP -update -support(免费)使使用SFTP的自动更新成为可能,而不需要libssh2。因此,除非在极少数需要的情况下,上述权限永远不必放松。

我认为下面的规则是推荐的默认wordpress网站:

对于wp-content中的文件夹,设置0755权限: chmod -R 0755插件 chmod -R 0755上传 chmod -R 0755 upgrade 让apache用户成为wp-content目录的所有者: Chown apache上传 Chown apache升级 Chown apache插件

我不能告诉你这是否正确,但我在谷歌计算应用程序引擎上使用Bitnami图像。我有插件和迁移的问题,并进一步搞砸了chmod'ing权限后,我发现这三行解决了我所有的问题。不确定这是否是正确的方法,但对我来说很有效。

sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/
sudo find /opt/bitnami/apps/wordpress/htdocs/ -type f -exec chmod 664 {} \;
sudo find /opt/bitnami/apps/wordpress/htdocs/ -type d -exec chmod 775 {} \;

对于OS X使用以下命令:

sudo chown -R www:www /www/folder_name