Skip to main content

640

640 Permission Code**

Permission Code: 640 Owner Read/Write, Group Read, Public No Access

640 grants read/write to the owner, read-only to the group, and **no access to others.

rw-r-----

This is a **hardened file permission used when you want the web server group to read files but prevent any access from the public. Its a common choice for sensitive, non-executable files on a WordPress VPS when the web server runs in the same group as the site user.

Technical Structure

NoRoleBitsAccessAllowed?
1Ownerrw-read/write
2Groupr--read-only
3Others---no access

Behavior

  • Owner can edit files.
  • Web server (if in the group) can read files to serve PHP/HTML.
  • Public users on the system have no read or list access to these files.
  • Useful for **configs, logs, caches, and private content that must be server-readable but not world-readable.

WordPress Use Cases

NoLocation/TypeSuitabilityReason
1wp-config.php (with group = webserver)server reads, others blocked
2.env or private app configssensitive values, server-only read
3Cache manifests and generated configsserver must read; public blocked
4PHP files in public treesafer than 644 if group is correct
5Public assets (images, css, js)may need world-read on some stacks

If your web server user isnt in the files group, 640 may break reads. Align ownership.

Comparison With Neighbor Modes

NoModeOwnerGroupOthersTypical UseNotes
1644rw-r--r--standard WP filessimpler, world-readable
2640rw-r-----hardened WP filesrequires correct group
3600rw-------secrets/configsmaximum restriction

Ownership & Group Model (Critical)

To use 640, set the **group to the web server (e.g., www-data for OLS/NGINX/Apache):

chown -R wpuser:www-data /var/www/your-site

This ensures the web server can read files that are 640.

Commands for Applying 640 Safely

Harden specific sensitive files

chmod 640 wp-config.php
chmod 640 .env

Apply broadly to files (only if group is correct)

find . -type f -exec chmod 640 {} ;

Keep directories traversable

find . -type d -exec chmod 750 {} ;

Minimum secure alternative (if group not aligned)

find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;

Practical Patterns

  • **Hardened baseline for private sites or controlled VPS:
  • Directories: 750
  • Files: 640
  • wp-config.php: 600
  • **Standard baseline for widest compatibility:
  • Directories: 755
  • Files: 644
  • wp-config.php: 600

Troubleshooting

NoSymptomLikely CauseFix
1Blank pages / 403web server not in groupadd server user to group or chown to :www-data
2WP CLI read errorsCLI user not owner/grouprun as site user or adjust group
3Static assets not servedasset files at 640 on strict stackuse 644 for public assets, keep configs at 640
4Plugin cannot read configplugin runs under different user/groupalign ownership; avoid world-read

Verification Steps

stat wp-config.php
# Expect: Access: (0640/-rw-r-----) Uid: (wpuser) Gid: (www-data)

ps aux | grep -E 'nginx|lshttpd|apache'
# Confirm which user/group serves the site

id www-data
# Confirm group memberships

Exercise (Safe Environment)

  1. Align ownership and group:

    chown -R wpuser:www-data /var/www/your-site

  2. Apply hardened set:

    find . -type d -exec chmod 750 {} ;
    find . -type f -exec chmod 640 {} ;
    chmod 600 wp-config.php

  3. Test site access and WP-CLI usage as wpuser.

  4. If static assets fail, revert assets to 644 while keeping configs at 640/600.

Key Takeaways

NoStatementStatus
1640 blocks public read while allowing group read
2Requires correct group ownership (:www-data)
3Good for configs, caches, private files
4May break static assets on some stacks
5Combine with 750 directories and 600 for wp-config.php