QUESTIONS CENTRECategory: CentosHow to Set all directories to 755 And all files to 644
zenhost Staff asked 11 months ago

It is always advised to keep the file and directory permissions to minimal. May of the web application framework suggest to keep permissions for all directories to 755, and all files to 644.


Change directory with cd command to the desired location under with you need to all directories to 755, and all files to 644 permissions.

cd /home/user/public_html


Then use first command to chmod 755 for all directories and sub directories. The second command will change all the files permission to 0644 (chmod 644) under the directory tree.

find . -type d -exec chmod 0755 {} \; 

find . -type f -exec chmod 0644 {} \; 


You can also change permission using xargs command to do this quickly.

find . -type d -print0 | xargs -0 chmod 755  

find . -type f -print0 | xargs -0 chmod 644 

Change Permission for Specific files

Instead of changing permission for all files, you can also target the specific files with similar extensions. For example you have PHP application on your server. And you don’t want to allow others to execute php files.

Then use the following command to chmod 0640 to all file with php extension:

find . -type f -name "*.php" -exec chmod 0640 {} \; 

The file permission 0640 will restrict others with no permissions. This will add an extra layer of permissions.