I've had a look over here but didn't find any details on the best file permissions. I also took a look at some of WordPress's form's questions over here too but anybody that suggests 777 obviously needs a little lesson in security.
In short my question is this. What permissions should I have for the following:
- root folder storing all the WordPress content
- wp-admin
- wp-content
- wp-includes
and then all the files in each of those folders?
To absolutely make sure that your website is secure and you are using correct permissions for your folders, use a security plugin like these:
https://en-ca.wordpress.org/plugins/all-in-one-wp-security-and-firewall/
https://en-ca.wordpress.org/plugins/wordfence/
These plugins will scan your Wordpress installation and notify you about any potential issues. These will also warn you about any insecure folder permissions. In addition to that, these plugins will recommend you what permissions should be assigned to the folders.
Based on all the reading and agonizing on my own sites and after having been hacked I have come up with the above list that includes permissions for a security plugin for Wordpress called Wordfence. (Not affiliated with it)
In our example, the wordpress document root is /var/www/html/example.com/public_html
Open up the permissions so that www-data can write to the document root as follows:
Now from the dashboard in your site, as an admin you can perform updates.
Secure Site after Updates are finished by following these steps:
The above command changes permissions of everything in the wordpress install to the wordpress FTP user.
The above command ensures that the security plugin Wordfence has access to its logs. The uploads directory is also writeable by www-data.
The above command also ensures that the security plugin has required read write access for its proper function.
Directory and Files Permissions
Set the permissions for wp-config.php to 640 so that only wp-user can read this file and no one else. Permissions of 440 didn't work for me with above file ownership.
Wordpress automatic updates using SSH were working with fine with PHP5 but broke with PHP7.0 due to problems with php7.0-ssh2 bundeld with Ubuntu 16.04 and I couldn't find how to install the right version and make it work. Fortunately a very reliable plugin called ssh-sftp-updater-support (free) makes automatic updates using SFTP possible without need for libssh2. So the above permissions never have to be loosened except in rare cases as needed.
For OS X use this command: