• Posted: 16-07-2025
  • Last Updated: 28-07-2025
  • Category: Server Guides

Incorrect file and directory permissions are a common issue that can lead to display errors or, more seriously, create security vulnerabilities. This article will guide you on how to use the find command to bulk CHMOD permissions quickly and accurately.

Why Use CHMOD 644 for Files and 755 for Directories?

This is the standard and secure permission set for most web hosting environments:

  • Files (644): Only the owner has write permissions (edit/delete), while other users can only read. This prevents others from modifying your source code.
  • Directories (755): The owner has full permissions. Other users have read and execute permissions, which is necessary for the web server to enter the directories and serve the files within.

1. Common CHMOD Use Cases

Below are commands you can use directly. Remember to replace /home/username/public_html with your actual path.

Use Case 1: Reset All Permissions to Standard

This is the most common task when you want to clean up and ensure all source code has the correct permissions.

- Set all FILES to 644:

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

- Set all DIRECTORIES to 755:

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

Use Case 2: Fix Incorrect and Insecure Permissions

Sometimes, you only want to find and fix files/directories with specific incorrect permissions, such as 666 or 777.

- Find files with 666 permissions and change them to 644:

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

- Find directories with 777 permissions and change them to 755:

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

Use Case 3: Apply to All Users

If you are a server administrator and want to perform this for all user accounts in the /home directory, you can replace the username with a wildcard character *.

# CHMOD all files for all users to 644
find /home/*/public_html -type f -exec chmod 644 {} ;

# CHMOD all directories for all users to 755
find /home/*/public_html -type d -exec chmod 755 {} ;

Important Warning

The find command combined with -exec is very powerful. Always double-check your path before executing the command, especially when using root privileges (sudo) or a wildcard (*). A small mistake can change permissions across your entire system and cause critical errors.

Share:
Rating:

( Total: 1 ratings. Average 5, scale: 1 to 5 )