我在这里看了一下,但没有找到关于最佳文件权限的任何细节。我也在这里看了一些WordPress表单的问题,但任何建议777的人显然需要上一节安全课。
总之,我的问题是这样的。我应该拥有以下权限:
存储所有WordPress内容的根文件夹 wp-admin wp-content wp-includes
那每个文件夹里的所有文件呢?
我在这里看了一下,但没有找到关于最佳文件权限的任何细节。我也在这里看了一些WordPress表单的问题,但任何建议777的人显然需要上一节安全课。
总之,我的问题是这样的。我应该拥有以下权限:
存储所有WordPress内容的根文件夹 wp-admin wp-content wp-includes
那每个文件夹里的所有文件呢?
当前回答
chown -Rv www-data:www-data
chmod -Rv 0755 wp-includes
chmod -Rv 0755 wp-admin/js
chmod -Rv 0755 wp-content/themes
chmod -Rv 0755 wp-content/plugins
chmod -Rv 0755 wp-admin
chmod -Rv 0755 wp-content
chmod -v 0644 wp-config.php
chmod -v 0644 wp-admin/index.php
chmod -v 0644 .htaccess
其他回答
最好在https://wordpress.org/support/article/changing-file-permissions/上阅读wordpress文档
All files should be owned by the actual user's account, not the user account used for the httpd process Group ownership is irrelevant, unless there's specific group requirements for the web-server process permissions checking. This is not usually the case. All directories should be 755 or 750. All files should be 644 or 640. Exception: wp-config.php should be 440 or 400 to prevent other users on the server from reading it. No directories should ever be given 777, even upload directories. Since the php process is running as the owner of the files, it gets the owners permissions and can write to even a 755 directory.
文件的正确权限是644 文件夹的正确权限为755
要更改权限,请使用terminal和以下命令。
find foldername -type d -exec chmod 755 {} \;
find foldername -type f -exec chmod 644 {} \;
文件夹是755,文件是644。
为了确保您的网站是安全的,并且您为文件夹使用了正确的权限,请使用如下安全插件:
https://en-ca.wordpress.org/plugins/all-in-one-wp-security-and-firewall/
https://en-ca.wordpress.org/plugins/wordfence/
这些插件会扫描你的Wordpress安装,并通知你任何潜在的问题。这些还将警告您任何不安全的文件夹权限。除此之外,这些插件会建议你应该给文件夹分配什么权限。
命令:
chown www-data:www-data -R *
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
ftp-user是用来上传文件的用户
chown -R ftp-user:www-data wp-content
chmod -R 775 wp-content
当你设置WP时,你(web服务器)可能需要对文件进行写访问。因此,访问权限可能需要放宽。
chown www-data:www-data -R * # Let Apache be owner
find . -type d -exec chmod 755 {} \; # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \; # Change file permissions rw-r--r--
安装完成后,您应该加强访问权限,根据加固WordPress,除了wp-content之外的所有文件都应该只能由您的用户帐户写入。Wp-content也必须可以被www-data写入。
chown <username>:<username> -R * # Let your useraccount be owner
chown www-data:www-data wp-content # Let apache be owner of wp-content
也许稍后您想更改wp-content中的内容。在这种情况下你可以
使用su临时更改用户为www-data, 给予wp-content组写权限775,并加入www-data组或 给您的用户使用acl访问文件夹的权限。
无论你做什么,确保文件对www-data有rw权限。