Skip to main content

File vs Directory Permissions

File vs Directory Permissions How They Behave Differently

Files and directories follow the same permission bit system, but the effect of r, w, x is **completely different between them. Misunderstanding this is one of the top causes of WordPress upload, plugin install, CLI, and SSH access issues. This module ensures you never break file access on your VPS.

What You Will Learn

  • Difference between file and directory permission behavior.
  • How r, w, x apply differently on files vs folders.
  • Why directories require x to enter.
  • WordPress-specific consequences (uploads, plugins, wp-cli).
  • Real secure production permission examples.
  • Debugging matrix + command lab + checks.

5W + 1H Framework

QuestionAnswer
Whatdistinction between file and directory permissions
Whyreading, editing, uploading, executing WP tasks
Where/var/www/, wp-content/, logs, scripts
Whendeployments, fixing upload issues, security hardening
Whoowner / group / www-data / dev users
Howusing chmod + understanding bit semantics

Core Principle

Files = content access

Directories = container access (enter, list, modify)

Even if a file is readable, you cant access it if directory permissions block you.

Permission Semantics Table

For Files

BitMeaning
rcan read file contents
wcan modify file contents
xcan execute file (scripts, binaries)

For Directories

BitMeaning
rlist files (ls)
wcreate/delete/rename files in it
xenter directory (cd, access files)

Directory Execute (x) = Access Permit / Door Key

Without x, directory is visible but inaccessible.

Practical Real-World Comparison

ActionFile NeedsDirectory Needs
Read file contentrx
Edit filewx
Run scriptxx
List directoryr + x
Enter directoryx
Create/delete filew + x

WordPress-Specific Rules

FunctionRequired Permission
View site contentfiles need 644
Upload imageswp-content/uploads needs 755
Install plugins/themesdirectories need x
Run wp-clifiles 644, dirs 755
Secure wp-config600

WP Standard Permissions (Numeric)

TypeRecommended
Files644
Directories755
wp-config.php600

WP Standard Permissions (Symbolic)

TypeRecommended
Fileschmod u=rw,go=r
Directorieschmod u=rwx,go=rx
wp-config.phpchmod u=rw,go=

Command + Expected Output

Set correct WP perms

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

Check:

ls -l

Expected snippet:

-rw-r--r-- wp-settings.php
drwxr-xr-x wp-content
-rw------- wp-config.php

Common Misconfig Mistakes

MistakeResult
Directory 644Cannot enter folder, WP breaks
Files 755Public executes, security risk
uploads 644Cannot upload images
wp-config 777Critical security hole

Static vs Dynamic Approach

ModeWhen
Static (644/755)production default
Dynamic permission patchtroubleshooting uploads/plugins
Harden config (600)after setup

Go-Live Checklist

CheckCommand
File permsfind . -type f -perm 777
Dir permsfind . -type d -perm 777
Config permsstat wp-config.php
Directory traversalls -ld wp-content/

Goal:

files readable, directories traversable, config locked.

Troubleshooting Matrix

SymptomRoot CauseFix
Uploads failmissing x on directorieschmod -R 755 wp-content/uploads
Plugins failwrong folder permsfind . -type d -exec chmod 755 {} ;
403 forbidden browsing dirs+x missingchmod a+X wp-content
WP CLI fails creating filesno write on dirchmod g+w wp-content/uploads

Quick Lab

Fix core WP perms & test directory traversal

cd /var/www/your-site/public_html

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

ls -ld wp-content/
ls -l wp-config.php

Verify success:

  • /wp-content/ is drwxr-xr-x
  • wp-config.php is rw-------

Cheat Sheet

Files → need r to read, w to edit, x to execute
Directories → need x to enter, r to list, w to create/delete

Essential:

Files: 644
Directories: 755
wp-config: 600

Mental rule:

x on files = execute script

x on directories = enter the folder

Mini-Quiz

  1. Directory without x?
  • Can't enter
  1. File without r?
  • Can't read
  1. Directory listing requires?
  • r + x
  1. WP folders default?
  • 755
  1. wp-config secure mode?
  • 600