Site AI Auditde la Internet Solutions

File Permissions on a Web Server: Safe Settings Explained

1 octombrie 20267 min de cititSecuritate și SSL
File Permissions on a Web Server: Safe Settings Explained

Short answer: On most Linux web servers, safe defaults are 644 for files, 755 for directories and 600 or 640 for files containing secrets, such as configuration files with database passwords. Files should be owned by the site’s own user account, and the web server should be able to write only to the folders that genuinely need it, such as uploads and cache. Never use 777: it lets any process on the server change your files and usually hides an ownership problem that should be fixed instead.

Why file permissions matter

A website is a collection of files on a server: application code, themes, plugins, configuration, uploaded images and cache. Permissions decide which users and processes may read, change or run each file. They are one of the quiet foundations of website security:

Correct permissions do not stop every attack, but they limit how far an attacker gets. Many clean-ups after a hack, as described in the website recovery plan, end with resetting permissions for exactly this reason.

How Linux permissions work

Every file and directory has an owner, a group and three sets of permissions:

For each of these, three rights can be granted: read (r = 4), write (w = 2) and execute (x = 1). Adding the numbers gives one digit per set, so three digits describe the whole permission. For directories, “execute” means the right to enter the directory and access files inside it.

ValueOwnerGroupOthersTypical use
644read, writereadreadNormal files: PHP, HTML, CSS, JS, images
755read, write, enterread, enterread, enterNormal directories
640read, writereadnoneConfig files when the web server reads via group
600read, writenonenoneConfig files and secrets read by the owner only
400 / 440readnone / readnoneExtra-strict config files that rarely change
777everythingeverythingeverythingNever on a live website

Ownership matters as much as permissions

The numbers only make sense together with ownership. There are two common hosting set-ups:

  1. The site runs as its own user. Most shared hosting and many managed platforms run PHP under the account’s own user. Files owned by that user with 644 and 755 are readable and writable by the site, and other accounts on the server cannot change them.
  2. The web server runs as a shared user such as www-data, while files are owned by a separate deploy user. Code is then read-only for the web server, and only specific directories, such as uploads and cache, are owned by or writable for the web server user.

The second model is stricter: even if an attacker runs code through the website, they cannot change the application files. The trade-off is that updates must be done by the deploy user, not through the CMS admin panel.

The most common mistake is fixing an “unable to write” error by setting 777 instead of correcting ownership. The error almost always means the file belongs to the wrong user, for example after files were uploaded as root or copied from another server.

Recommended settings for a typical CMS

For WordPress and similar PHP applications, a sensible baseline is:

Files that should not be publicly reachable at all, such as .env files, database dumps and old archives, are a separate risk. See exposed .env, .git and backup files for how to find and block them.

How to check and fix permissions

Most hosting control panels show permissions in their file manager, and FTP or SFTP clients display them as a column you can change. With SSH access, you can list permissions with ls -l and reset them in bulk from the site’s root directory:

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
chmod 600 wp-config.php

Before running bulk commands:

  1. Take a backup and make sure you can restore it. The website backup strategy explains how.
  2. Run the commands in the right directory. Running them in the wrong place, especially as root, can break the server.
  3. Check ownership first with ls -l. If files belong to root or another account, fix ownership with your host’s help, or with chown if you manage the server.
  4. Test the site afterwards: front end, admin login, image uploads, plugin updates and any caching.

Stop scripts running from the uploads folder

Upload folders are the classic hiding place for malicious scripts, because they must be writable. Blocking script execution there removes most of the danger even if someone manages to upload a PHP file.

Combine this with disabling directory listing, so nobody can browse your folders; see how to disable directory listing.

Common mistakes and how to avoid them

Warning signs of permission problems

Where Site AI Audit fits

File permissions are set inside your server, so no outside scan can read them directly. What Site AI Audit checks from the outside are related symptoms visitors and attackers can see: exposed software versions, missing security headers, the SSL certificate and the HTTPS redirect. It explains each finding in plain words, and if you prefer not to touch the server yourself, the report’s “Fix it for me” option lets you request an estimate from Internet Solutions. You can run a free check first.

Related reading

The bottom line

Use 644 for files, 755 for directories and 600 or 640 for configuration secrets, with files owned by the site’s own user. Let the web server write only where it must, block script execution in uploads, and never use 777. When something cannot write, fix ownership, not permissions.

FAQ

What are the correct file permissions for a website?

For most Linux hosting, 644 for files and 755 for directories, with configuration files containing passwords set to 600 or 640. Ownership should belong to the site’s own user account.

Why is chmod 777 dangerous?

It gives every user and process on the server permission to change the file or folder. Attackers who get any foothold can then modify your code, and on shared servers other accounts may be able to as well.

What permissions should wp-config.php have?

Usually 600 or 640, depending on how the server runs PHP. Some hosts use 400 or 440 for extra safety. It should never be readable by other accounts on the server.

Why does WordPress ask for FTP details when updating plugins?

It usually means PHP cannot write to the plugin folders, often because files are owned by a different user. Fixing ownership is better than loosening permissions.

Can wrong permissions get my website hacked?

They rarely cause the first break-in, but they decide how much damage follows. Writable code folders and executable uploads let attackers plant backdoors that survive updates.

#Hacked website#Web hosting#Website security#WordPress security
Verifică-ți propriul site — gratuit.Ce să repari pe site — și de unde să începi.
Începe gratuit

Mai multe de pe blog

Toate articolele →
Internet Solutions

Mai multe de la echipa noastră

Create de Internet Solutions. Încearcă și celelalte produse ale noastre — fiecare îți economisește timp în alt fel.

internet-solutions.net ↗
Site AI Audit
Prezentare generală a confidențialității

Acest site folosește cookie-uri pentru a-ți oferi cea mai bună experiență posibilă. Informațiile din cookie-uri sunt stocate în browserul tău și îndeplinesc funcții precum recunoașterea ta când revii pe site și ajutarea echipei noastre să înțeleagă ce secțiuni ale site-ului găsești cele mai interesante și utile.