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. So this tutorial will help you to do this.

Change 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. 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. You can also change permission using xargs command to do this quickly. Here directory permission 0755 is similar to “rwxr-xr-x” and file permission 644 is equal to “rw-r–r–“.

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: The file permission 0640 will restrict others with no permissions. This will add an extra layer of permissions.

Conclusion

In this tutorial, you have learned to chmod all files or directories available under a directory tree.