The Security Risk of 777
In the Linux permission system, “777” means that every single user on the system—including anonymous web visitors and background daemon processes—has absolute permission to read, modify, and execute a file. While setting a folder to 777 is a common, lazy troubleshooting step when trying to fix file upload errors on a web server, leaving it that way creates a massive security vulnerability. A malicious actor could easily upload a reverse shell script into a 777 directory and execute it, taking complete control of your machine. To secure your Ubuntu server, you must periodically scan your entire filesystem to find any files or directories that have been carelessly assigned dangerous permission levels.
Using the find Command with -perm
The standard Linux find command includes a highly specific -perm (permissions) flag designed exactly for this type of security audit.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- Determine the directory you want to audit. To search the main web server directory, you would use
/var/www/. - Type the following command:
sudo find /var/www/ -type f -perm 777- Press Enter and provide your administrator password.
Refining the Search
-type fensures the command only returns files. To search for horribly insecure directories instead, change this to-type d.-perm 777tells the command to look for an exact match. It will only return files that have precisely 777 permissions.
Fixing the Permissions Automatically
If the command returns a massive list of insecure files, you can instantly fix all of them by piping the find output directly into the chmod (change mode) command. For example, to find all 777 files and instantly downgrade them to a secure 644 permission level (owner can read/write, everyone else can only read), use this command:
sudo find /var/www/ -type f -perm 777 -exec chmod 644 {} +
This single line of code will instantly plug the security holes across your entire web directory.