How to Find Files by Permission Level in Ubuntu

The Security Audit

If you are managing an Ubuntu server, one of the most dangerous security vulnerabilities you can create is accidentally granting global read, write, and execute permissions to a sensitive file or directory (known as “777” permissions). If a web application or a rogue script creates a file with these permissions, anyone who gains access to the machine can instantly overwrite it. To secure your server, you must regularly audit your filesystem to find any files that are improperly exposed. You cannot do this by randomly clicking through folders; you must instruct the kernel to search explicitly for the permission attribute.

Using the find Command with -perm

The Linux find command utilizes the -perm flag to filter files based exactly on their octal permission code.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the main web directory (/var/www/) for any files that have full 777 permissions, type the following command:
  3. sudo find /var/www/ -type f -perm 0777
  4. Press Enter and provide your administrator password.

Understanding the Syntax

The terminal will output a precise list of file paths that match the exact permission code.

  • -type f: This restricts the search to standard files. If you want to search for insecure folders instead, change this to -type d (for directory).
  • -perm 0777: The leading zero is often required for exact octal matching in modern versions of the find command. 777 means the User, Group, and completely unauthenticated “Others” all have permission to Read, Write, and Execute the file.

Once you identify these insecure files, you can immediately lock them down using the chmod command (e.g., chmod 644 filename.php).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.