Recursive chmod / Permission Change Across Directories for a File Type

Server Maintenance | Updated 2026

This guide provides the commands for recursively changing file and directory permissions across a hosting account. Useful for fixing permission issues after migrations, restores, or mass file uploads.

01. Standard Web Hosting Permissions

  • Directories: 755 (owner rwx, group rx, world rx)
  • Files: 644 (owner rw, group r, world r)
  • CGI/Perl scripts: 755 (must be executable)
  • Config files with passwords: 600 or 640
  • WordPress wp-config.php: 600 or 640
Never Use 777

On CloudLinux/cPanel servers, 777 permissions are rejected by Apache/LSAPI as a security measure. Files set to 777 will return a 500 error. Use 755 for directories and 644 for files.

02. Recursive chmod Commands

Set All Directories to 755

find /home/username/public_html -type d -exec chmod 755 {} \;

Set All Files to 644

find /home/username/public_html -type f -exec chmod 644 {} \;

Both at Once

find /home/username/public_html -type d -exec chmod 755 {} \; -o -type f -exec chmod 644 {} \;

Faster Alternative with xargs

find /home/username/public_html -type d -print0 | xargs -0 chmod 755
find /home/username/public_html -type f -print0 | xargs -0 chmod 644
Performance

The xargs method is significantly faster on accounts with many files because it batches the chmod calls instead of forking a new process for each file.

03. Using find for Granular Control

Change Only PHP Files

find /home/username/public_html -name "*.php" -exec chmod 644 {} \;

Make CGI Scripts Executable

find /home/username/public_html/cgi-bin -name "*.cgi" -exec chmod 755 {} \;
find /home/username/public_html/cgi-bin -name "*.pl" -exec chmod 755 {} \;

Secure Config Files

find /home/username/public_html -name "wp-config.php" -exec chmod 640 {} \;
find /home/username/public_html -name "configuration.php" -exec chmod 640 {} \;
find /home/username/public_html -name ".htaccess" -exec chmod 644 {} \;

04. Fixing Ownership

After a restore or migration, files may be owned by the wrong user:

# Fix ownership for the entire account
chown -R username:username /home/username/public_html/

# Fix ownership for a specific addon domain
chown -R username:username /home/username/addondomain.com/
cPanel Fix Permissions

cPanel includes a built-in tool to reset permissions for an account:

/scripts/fixperms username

This resets home directory, public_html, mail, and other standard directories to cPanel's expected permissions.

Need Permission Help?

If you are seeing 403 or 500 errors related to permissions, our team can fix them for you.

Open a Support Ticket

Quick Recap

  1. Directories: 755 via find -type d -exec chmod 755
  2. Files: 644 via find -type f -exec chmod 644
  3. Never 777 on shared hosting
  4. Fix ownership: chown -R username:username
  5. Or use: /scripts/fixperms username

5,186 users found this article useful · Last updated March 2026 · Browse all Server Maintenance articles

  • 118 Users Found This Useful

Was this answer helpful?

Related Articles

Clear cPanel Eximstats DB and Repairing the Eximstats DB

Server Maintenance | Updated 2026 The Eximstats database in cPanel tracks email delivery...

Error: rpmdb Open Failed with cPanel

Server Maintenance | Updated March 2026 The "rpmdb open failed" error means the RPM database...

Remount /tmp with exec permission

Server Maintenance | Updated 2026 Some software installations and compilation tasks require...

Killing cPanel Backups via Command Line / Shell

Server Maintenance | Updated 2026 When a cPanel backup process hangs or runs too long, it can...

Error: Multilib Version Problems Found

Server Maintenance | Updated March 2026 "Multilib version problems" is a yum error that...



Save 30% on web hosting - Use coupon code Hosting30