Incorrect file and directory permissions are a common issue that can lead to display errors or, more seriously, create security vulnerabilities. Manually changing permissions one by one is time-consuming, but fortunately, you can use the powerful find command to bulk CHMOD quickly and accurately.
This article will guide you through the necessary commands to perform this task safely.
1. Why Use CHMOD 644 for Files and 755 for Directories?
This is the standard and secure permission set for most web hosting environments:
2. 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:
- Set all DIRECTORIES to 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 directories with 777 permissions and change them to 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 *
.
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 {} ;
3. 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.
4. Conclusion
Using the find
command is an extremely effective way to manage and fix bulk permissions on Linux. By mastering the commands above, you can ensure your file system is always set up securely and correctly, helping your website run stably and safely.
Permission management is a critical part of server administration. If you want a pre-configured and professionally supported environment, consider the Vietnam Hosting and KVM VPS plans at VietHosting.