Prioritising security is crucial, as it ensures the protection of your files on your systems. Nobody wants their hard work to be misused due to simple errors. Often, newcomers set file permissions to 777 on production servers to avoid any permission problems. However, this is a significant mistake, as it grants writable permissions to everyone. You can refer to the previous tutorial on searching files with 777 permissions on a Linux system.

It is highly recommended to maintain minimal file and directory permissions. Many web application frameworks advise setting permissions for all directories to 755, and all files to 644. This tutorial will guide you through the process of implementing these recommendations.

Change File and Folder Permissions Recursively

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 {} \;

Change Permission for Specific files

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