Best practices for preventing permission errors on file servers

  • Always apply strong permissions (644 on files, 755 on directories) and especially protect sensitive files such as wp-config.php.
  • Properly configure owner and group (chown) so that the web server can read and write only where strictly necessary.
  • Avoid 777 permissions and periodically audit the file system to detect unsafe values ​​after migrations or changes.
  • Relate HTTP error codes to permission problems to quickly diagnose 403, 500 errors and upload or update problems.

Best practices for file server permissions

When you manage a file server or a WordPress installation, file and folder permissions are like the locks on a house: if you leave them wide open, anyone can walk in; if you lock them too tightly, even you won't be able to access what's inside. Even so, they remain one of those topics that are taken for granted, hastily configured on day one… and never revisited until a 403 or 500 error appears, or worse, a hack occurs.

This article gathers and reorganizes, in simpler terms, all the key information about permissions on Linux servers and in WordPress : how they work, what values ​​are safe, what typical errors they cause (403, 500, upload problems, update failures, etc.), and, above all, what best practices you should follow to prevent permission errors on file servers. The idea is that you can apply these guidelines whether you manage a simple shared hosting account or a VPS with multiple sites.

What are file permissions and why do they matter so much?

In Unix/Linux-like systems, each element of the file system (regular files, directories, scripts, etc.) has an associated owner, group, and a triple combination of permissions that determines who can read, write, or execute that resource. This combination is the first line of defense for any web server and, at the same time, a constant source of errors when misconfigured.

Permissions determine three basic operations: reading (r), writing (w) and execution (x)They are defined separately for the file owner, the group it belongs to, and other users. You can see it at a glance with Ls -l: a typical exit like -rw-r--r-- This means that the owner can read and write, while the group and others can only read.

In the case of directories, there's a peculiarity that causes a lot of confusion: execute permission in a directory doesn't mean "running" a program , but rather having permission to "traverse" that folder and access its contents. You can have read permission, but if the 'x' is missing at any point in the path, you won't be able to list or open anything within that directory.

In short, these permissions are usually expressed in three-digit octal notation , which you'll see frequently in web hosting and documentation: each position (owner, group, others) adds up to 4 for read, 2 for write, and 1 for execute. Thus, 7 is rwx, 6 is rw-, 5 is rx, and 4 is r-. This results in combinations like 644 or 755, which are the defaults on any well-configured file server.

server

Secure standard permissions for file servers and WordPress

If there's one rule that practically never fails on a Linux web server with PHP and WordPress, it's this: 644 for files and 755 for directories . This combination allows the web server to read what it needs to read, prevents anyone from modifying the code haphazardly, and avoids many HTTP errors resulting from incorrect permissions.

When a file is set to 644, the translation is simple: the owner can read and write, while the group and everyone else can only read . This works perfectly for PHP, HTML, CSS, image, library, and other files. No one other than the owner can overwrite critical site files, while the web server can serve them without issue.

Directories, on the other hand, require execution to be traversed, so the typical value is 755 (rwxr-xr-x) . The owner has full control over the folder; the group and others can enter and read its contents, but only the owner can create, modify, or delete items within it. This strikes the right balance between functionality and security for a hosting environment.

In WordPress, this convention applies to virtually the entire structure: core files, themes, plugins, and scripts They use 644, while folders like wp-admin, wp-includes o wp-content They are left at 755. There are only a few exceptions which we will discuss in detail, but if you start from 644/755 you are already within good practices.

The role of the owner and the group: chown and user organization

Permissions alone are meaningless without considering who owns the files and which group they belong to . On a web server, the user running the server (www-data on Debian/Ubuntu, apache on CentOS/RHEL, nginx in some environments) must at least be able to read the files it serves and, in certain paths, also write to them.

In a healthy environment, the The owner of the files is usually your system or FTP user (the one who uploads and maintains the code), while the group is assigned to the web server user. The typical scheme would be something like this: tu_usuario:www-data for the entire WordPress tree or your application, so that you can edit and the server can read without further complications.

To adjust this, you use chown (change owner)This is a powerful command that should be handled with care because only root can use it without restrictions. The most common pattern after deploying a site is something like this: chown -R tu_usuario:www-data /ruta/a/wordpressFrom there you apply the 644/755 permissions policy and ensure that the web server does not go blind.

In shared hosting, the web server user often coincides with your user , and there the room for maneuver is less: you won't be able to change owners at will, but at least you'll know that if WordPress can't write to a folder, the problem will be more in the permissions than in the user.

wp.config.php

Critical special cases: wp-config.php, uploads, and other sensitive points

Within a WordPress site, not all files are equally sensitive. Some, if misconfigured, can turn your file server into an open invitation to attacks. The clearest example is wp-config.php , the file that stores database credentials and various security keys.

This file should always have more restrictive permissions than the rest . The usual setting is 600 (only the owner can read and write) or, if the server allows it, 440 (read for owner and group, no writing) so that even other system users can't access it. What should never happen is that wp-config.php appears with permissions of 644 or 755: if someone gains read access to the file system, they would have your database data in plain text.

There are also directories that need to be writable by the web server for WordPress to function correctly. The most obvious example is wp-content/uploads , where all images and files uploaded from the WordPress dashboard are stored, especially on NAS drives . This folder must be located at 755 and, furthermore, its owner must be the user running PHP or the appropriate FTP user; otherwise, you will see the typical "Cannot create directory" error.

If you use caching or backup plugins, directories like wp-content/cache y wp-content/backup They also need permissions that allow writing to the web server (usually 755) and the correct ownership. Many performance plugin failures stem from this: cache paths where PHP cannot save files due to incorrect permissions or ownership.

Why incorrect permissions are a real vulnerability

Setting permissions to 777 for a directory or file might solve a temporary write issue, but from a security standpoint, it's like leaving your front door open with a sign that says "come in anytime." Excessively broad permissions allow any process with access to the server to modify your code , including an attacker who has exploited a less obvious vulnerability.

A typical example: an outdated WordPress plugin with a file upload vulnerability. If the destination directory is under 777, an attacker can directly upload a malicious PHP script, execute it, and then inject code into any writable file, install persistent backdoors, or manipulate content to insert spam links or hidden redirects. If those same directories were under 755 and the files under 644, the potential damage would be much less.

Specific risks include altering key files such as wp-config.php or functions.php , stealing database credentials, manipulating redirects for organic traffic, compromising WooCommerce-based online stores, and the possibility of using your server as a foothold to attack other systems.

Recent studies on incidents at small websites show that a significant percentage of WordPress hacks are related to poorly configured hosting permissions . While not always the sole cause, these issues greatly facilitate an attacker's efforts. The good news is that this is a trivial problem to resolve if the site is audited and corrected promptly.

filezilla

Change permissions securely: SSH, FTP and hosting panel

To correct permissions on a file server, you have several options: an SSH connection and command line , an FTP/SFTP client like FileZilla , or the file manager in your control panel (cPanel, Plesk, your hosting provider's control panel, etc.). The choice will depend on what your hosting provider allows and how comfortable you feel with each tool.

If you have SSH access, the cleanest and fastest way to normalize permissions is to use `find` combined with `chmod` to treat files and directories separately. A common pattern used in WordPress installations would be:

find /ruta/a/wordpress -type d -exec chmod 755 {} \;
find /ruta/a/wordpress -type f -exec chmod 644 {} \;

These two commands restore the default values ​​for the entire directory tree, and then you can manually adjust the exceptions, for example by applying `chmod 600` to `wp-config.php` . This avoids the common mistake of using `chmod -R 644 /path`, which also removes execute permissions from directories and results in a flood of 403 errors.

If you only have FTP/SFTP access, the process is similar but more manual. In FileZilla, for example, you can right-click on a folder, choose "File permissions," and check the read/write/execute boxes for owner, group, and others , as well as apply the changes recursively to only directories or only files. It's slower, but sufficient for shared hosting where SSH is disabled.

Control panels like cPanel or Plesk offer a file manager with the option to change numeric permissions . They usually display a box where you directly enter 755 or 644, which is very convenient for checking current values ​​and correcting specific paths that are causing upload or write problems.

Common errors related to permissions and how to avoid them

Many file server problems follow the same pattern over and over. Understanding the most common errors and their relationship to permissions saves you a lot of time diagnosing and testing.

One of the classics in WordPress is the notice “Unable to create directory wp-content/uploads" or a similar message when trying to upload images to the site. Translated: The web server cannot write to the uploads folder. The first thing to check is that wp-content/uploads It has 755 and the property (user and group) matches the PHP user or at least the correct FTP user.

Another common mistake is using a "temporary" chmod 777 to "quickly fix" a problem, and then leaving it like that for weeks or months. It's the kind of hack that never fails: you set it to 777 on a Friday afternoon, forget about it on Monday, and half a year later the site is full of spam links because someone took advantage of the loophole. The best practice is to locate and fix the real cause (incorrect owners, misconfigured paths, scripts assuming impossible permissions) instead of opening the floodgates.

It's also common for someone to apply a recursive command without distinguishing between files and directories, for example, `chmod -R 644 /var/www/mysite` . The results are immediate: folders without execute permission, inability to access internal paths, and a cascade of 403 or 500 errors. That's why we emphasize the formula with `find` and separating `-type fy` and `-type d`.

Relationship between permissions, HTTP errors, and server stability

File permissions are closely tied to many HTTP status codes you see in your browser. Understanding this relationship allows you to diagnose 4xx and 5xx errors much more quickly, especially on shared servers and WordPress sites.

The 403 Forbidden error , for example, usually indicates that the web server doesn't have permission to read the file or to access a directory in the path. If a folder has been set to 700 or a file to 600 without considering that Apache or Nginx need to read it, the typical result is a 403. Checking file permissions (644) and directory permissions (755), along with the .htaccess rules, usually resolves most of these cases.

The dreaded 500 Internal Server Error can be caused by many things, but incorrect permissions are a frequent culprit. Some PHP modules or suPHP/PHP-FPM configurations refuse to run scripts with permissions 777 or 666 precisely for security reasons, returning a 500 error. Normalizing permissions to 644/755 and protecting sensitive files like wp-config.php is usually one of the first steps recommended by system administrators.

In the realm of SEO, 4xx and 5xx errors stemming from incorrectly configured permissions have a direct impact. A 404 error on a new URL with no inbound links isn't a major concern , but a 404 or 403 error on pages with valuable backlinks does imply a loss of authority and organic traffic.

In addition to server codes, modern browsers display messages such as ERR_TOO_MANY_REDIRECTS or ERR_CONNECTION_REFUSED when the problem is in the network, SSL, or misconfigured redirect loops.

Best practices for preventing permission errors on file servers

Given all the theory and typical pitfalls, it makes sense to establish a clear set of best practices to keep permission errors under control on any file server or WordPress installation. It's not just about fixing things when they break, but about setting up the system properly from the start.

The first recommended practice is to create a full backup before modifying permissions in a production environment. Many changes seem harmless until a poorly executed recursive chmod or chown command renders half the site inaccessible. Having a backup allows you to roll back changes without major issues if you make a typo.

Secondly, it's advisable to define and document a permissions policy for your servers: 755 for directories, 644 for files, and 600/640 for sensitive configurations like wp-config.php or SSH keys, with no makeshift exceptions. This policy can be integrated into deployment scripts (Ansible, bash, etc.) and version control systems like Git , so that each code update automatically applies the correct permissions.

The third leg is the periodic audit of permitsA simple find searches for files with 777 or with write permissions for a group or others (-perm /022This helps uncover vulnerable areas left open after migrations, manual restorations, or third-party actions. Performing this review every few months, or after major changes, significantly reduces the attack surface.

Finally, it's a good idea to complement this security layer with other measures such as keeping WordPress, plugins, and themes up to date, using SFTP instead of plain FTP, deploying a web application firewall (WAF), and having a backup and malware scanning system in place . Permissions are an essential barrier, but they aren't the only one; they work best as part of a coherent set of measures.

Close-up of programming code on a computer screen, representing permission settings in the Linux terminal.
Related article:
Proper permission management in Linux without compromising security

Add as preferred source in Google