Set Strong Permissions: Ensure Files Have the Correct Permissions (755 for Directories, 644 for Files)

Securing your WordPress website involves a variety of steps, and one of the most crucial but often overlooked measures is setting proper file permissions. File permissions dictate who can read, write, and execute files or directories on your web server. Incorrect file permissions can expose your website to various security risks, such as unauthorized access or malicious code injections. Setting strong file permissions ensures that only authorized users have access to sensitive files, helping safeguard your site from hackers.

In this article, we’ll explain what file permissions are, why they matter for WordPress security, and how to set appropriate file permissions to protect your website.

What Are File Permissions?

File permissions are rules that control how files and directories on your server can be accessed and modified. These permissions determine who can read (view the content), write (modify the content), and execute (run as a program) files and directories.

Permissions are typically represented by a three-digit number, such as 755 or 644, where each digit controls the access level for different user groups:

  1. Owner: The user who owns the file or directory (usually the account that created it).
  2. Group: A set of users who are assigned to a particular group.
  3. Public (or Others): Everyone else who accesses the server.

Each digit in the permission number represents the access rights for one of these groups, with the following values:

  • Read (4): Allows the file to be read or viewed.
  • Write (2): Allows the file to be modified.
  • Execute (1): Allows the file to be executed as a program.

The combination of these values gives you different permission levels. For example, a permission of 755 means:

  • The owner can read, write, and execute (7 = 4 + 2 + 1).
  • The group can read and execute (5 = 4 + 1).
  • The public can read and execute (5 = 4 + 1).

For most WordPress installations, directories should have a permission of 755, and files should have a permission of 644.

Why File Permissions Matter for WordPress Security

Setting correct file permissions is vital for protecting your WordPress website from unauthorized access and exploitation. If permissions are too loose, hackers could gain access to critical files, inject malicious code, or take control of your website. On the other hand, if permissions are too restrictive, your website might not function properly.

1. Prevent Unauthorized Access

Loose file permissions, such as 777 (which allows everyone to read, write, and execute a file), can give malicious actors the ability to modify your files and directories. This can lead to a variety of security breaches, including defacement, data theft, or even complete loss of control over your website.

By setting the correct permissions, you limit who can interact with your files, reducing the chances of unauthorized access. For example, a file with a 644 permission means that only the file owner can modify it, while others can only read it, preventing external users from altering critical website files.

2. Protect Sensitive Data

Certain files in a WordPress installation contain sensitive information, such as database credentials and configuration settings. The wp-config.php file, for instance, stores the database login details. If the permissions for this file are not set correctly, hackers could gain access to this information, leading to a potential breach.

Ensuring that sensitive files are properly protected by setting strong permissions helps keep your database credentials and other private data secure.

3. Reduce the Risk of Malicious Code Injections

Hackers often attempt to inject malicious code into a website by exploiting files with weak permissions. For example, they might add a backdoor or malware to a file that has write permissions enabled for the public or group users. This allows them to gain persistent access to your website, even after you think you’ve removed the threat.

By setting file permissions to 644, you prevent anyone other than the file owner from modifying website files, thereby reducing the risk of malicious code injections.

4. Ensure Proper Functionality

While securing your website is essential, it’s also important not to set permissions too restrictively. Doing so can prevent your website from functioning correctly. For example, if a directory’s permissions are too restrictive, WordPress may not be able to create or modify files as needed, resulting in errors or broken functionality.

Finding the right balance between security and functionality is key, which is why the 755 permission for directories and 644 for files is the standard recommendation.

How to Set Correct File Permissions in WordPress

Setting correct file permissions can be done in several ways, including using a file manager in your web hosting control panel (such as cPanel) or via FTP/SFTP. Here’s a step-by-step guide on how to set permissions using these methods:

1. Using cPanel File Manager

Most web hosting providers offer a control panel like cPanel that includes a file manager for managing your website’s files and directories. To set file permissions:

  1. Log in to your cPanel account and open the “File Manager.”
  2. Navigate to the root directory of your WordPress installation (usually public_html or a subfolder).
  3. Select the files or directories you want to modify.
  4. Right-click the file or directory and choose “Change Permissions.”
  5. In the pop-up window, set the permissions to 755 for directories and 644 for files.
  6. Save the changes.
2. Using FTP or SFTP

If you prefer using an FTP client like FileZilla, you can change file permissions as follows:

  1. Open your FTP client and connect to your server.
  2. Navigate to your WordPress root directory.
  3. Right-click on a file or directory and select “File Permissions.”
  4. A dialog box will appear, allowing you to set the permissions.
  5. Enter 755 for directories and 644 for files, then click “OK” to apply the changes.
3. Using the Command Line (For Advanced Users)

If you have SSH access to your server, you can set file permissions using command-line tools. The following commands can be used to set permissions:

  • To set 755 for all directories:

    bash
    find /path/to/your/wordpress/installation -type d -exec chmod 755 {} \;
  • To set 644 for all files:

    bash
    find /path/to/your/wordpress/installation -type f -exec chmod 644 {} \;

Be sure to replace /path/to/your/wordpress/installation with the actual path to your WordPress site.

Best Practices for File Permissions in WordPress

In addition to setting the basic 755 and 644 permissions, here are some best practices to further secure your WordPress site:

1. wp-config.php Permissions

The wp-config.php file contains sensitive information, including your database credentials. It’s recommended to set the permissions for this file to 440 or 400, ensuring that only the file owner can read it and no one else can access or modify it.

2. Disable File Editing

WordPress allows administrators to edit theme and plugin files directly from the dashboard. However, this feature can be a security risk if an attacker gains access to your admin account. You can disable this feature by adding the following line to your wp-config.php file:

php
define('DISALLOW_FILE_EDIT', true);
3. Regularly Monitor Permissions

Permissions can sometimes change unintentionally during updates or installations. It’s a good practice to regularly audit your file permissions to ensure they remain set correctly

Conclusion

Setting strong file permissions is a fundamental step in securing your WordPress website. By ensuring that directories have a permission of 755 and files have a permission of 644, you reduce the risk of unauthorized access, protect sensitive data, and safeguard your site from potential attacks. Regularly monitoring and adjusting file permissions as needed can help ensure that your website remains secure without compromising functionality.

Get InTouch with us

We’d love to hear from you! Whether you have questions about our services, need assistance, or want to provide feedback, we’re here to help.