You see a “Permission denied” error when trying to open a folder on your server. This confusion often stems from misunderstanding file permissions. The simple answer: 755 grants owner read, write, and execute rights, while 644 does not allow anyone to execute.

File permissions are crucial for security. Use 755 for folders and scripts, and 644 for static files like HTML and images. Mastering Linux file permissions helps you set the correct access levels. Your web server code relies on these settings. A secure server requires proper configuration for each application. Follow these rules to protect your data.

Understanding 755 Grants Owner Read, Write, and Execute

The Numeric System: Read, Write, Execute Values

A simple number code controls Linux file permissions. Each permission type has its own value: read is 4, write is 2, and execute is 1. You combine these numbers to form a permission set. For example, 7 means read, write, and execute (4+2+1). 5 means only read and execute (4+1). 4 means only read.

This system comes from the early days of computing. Octal notation started in the B language around 1969, on PDP-8 machines. Octal digits are still used today because each digit directly matches the three-bit permission set. When you run chmod 755, you are using the same octal system that programmers used long ago.

OctalBinary (rwx)Meaning
0000no permissions
1001execute only
2010write only
4100read only
7111read, write, execute

Breaking Down 755 and 644 Permission Sets

The three digits in a permission mode stand for three user groups. The first digit is for the owner, the second is for the group, and the third is for everyone else. With 755, the owner gets read, write, and execute rights. The group and others only get read and execute permissions.

Now compare with 644. The owner gets read and write access. The group and others only get read access. No one except the owner can execute anything. This difference is very important on your server.

User Class755 Permission644 Permission
GroupRead + ExecuteRead only
OtherRead + ExecuteRead only

Knowing how linux file permissions work helps you make good choices. The chmod command sets these permissions. You run chmod 755 for folders and chmod 644 for normal files. These linux file permissions keep your server safe from unwanted changes. The owner has full control, while others have limited access. This balance keeps your server secure and lets needed operations run.

The Execute Bit: Files vs. Directories

Why Execute Matters for Scripts and Programs

The execute bit changes how the system treats a file. For regular files, this permission determines whether you can run the file as a program. Without it, the system refuses to launch the file. You see an error message instead of the expected output.

Consider a CGI script on your web server. This script processes form data or generates dynamic content. The server must execute this file to produce results. If the script lacks execute permission, the server returns a “500 Internal Server Error” or a “Permission denied” message. You fix this problem by setting the correct mode with chmod 755.

Common scripts that need execute permission include:

  • CGI scripts (.cgi files): These require 755 permissions to run properly on the web server.
  • PHP output files generated by content management systems: Some servers need the execute bit set to at least 755. A default 666 permission causes errors.
  • Executable binaries: Installation tools and utility programs need chmod +x before you can run them.

Your application code often includes these executable files. The server needs proper access to run them. Without execute permission, your application fails silently or displays cryptic errors. You waste hours debugging when the real issue is a missing execute bit.

Why Directories Need Execute to Be Traversed

Directories behave differently from files. The execute bit on a directory controls your ability to enter it. Think of a directory as a room. The execute permission is the key that opens the door. Without the key, you cannot step inside, no matter what treasures the room holds.

This permission propagates downward. If a directory lacks execute permission for you, you cannot access any files or subdirectories inside it. Even if individual files have read permission, you cannot reach them. The directory blocks your path completely.

You might wonder why read permission alone does not suffice. Without execute permission on a directory, you cannot list its contents or access files inside it. The execute bit grants traversal rights. It allows the system to follow the path from one directory to another.

This behavior affects how linux file permissions work in practice. Your web server needs execute permission on every directory in the path to your files. For example, consider /var/www/html. The server must traverse /var, /var/www, and /var/www/html. If any directory lacks execute permission, the server cannot reach your content.

The owner of a directory typically sets permissions to 755. This mode gives the owner full access. Group members and others can read and traverse the directory. This setup works well for shared web hosting environments. It balances security with functionality.

You should remember this rule: directories always need execute permission to be accessible. Files only need execute permission if they contain code that runs. Static files like HTML pages or images do not need this bit. They only require read permission for the server to serve them.

This distinction prevents many configuration errors. When you understand the execute bit, you can diagnose permission problems quickly. You check the directory permissions first. Then you verify the file permissions. This systematic approach saves time and frustration.

The principle of least privilege guides your choices. Grant only the permissions necessary for each task. Your server needs execute access to directories and scripts. Your static content needs only read access. Apply this logic consistently across your entire system.

Using chmod 755 and 644 for Linux File Permissions

You control linux file permissions with the chmod command. The syntax follows a simple pattern. You type chmod followed by three digits and the file or folder name. For example, chmod 755 foldername or chmod 644 filename. This command changes the access rights for the group, owner, and others. Understanding chmod helps you apply the correct settings to your web server files. Your web server needs proper permissions to serve content without errors. Many beginners set permissions too loosely or too tightly. The right balance keeps your application code running smoothly.

Standard Use Cases for Web Files and Folders

A typical web server hosts many file types. Each type needs a different permission level. Your web server needs read access to serve static files. Your application code needs execute permission to run scripts. Your configuration needs protection from outside modification. You must understand these differences to set permissions correctly.

WordPress is a common example. WordPress folders use 755 permissions. The owner has full read, write, and execute rights. The group and others have read and execute rights only. WordPress files use 644 permissions. The owner can read and write. The group and others can only read. This setup works for most websites.

The table below shows the recommended file permissions for a WordPress installation:

File/Directory TypeRecommended Permission
Directories (public_html, wp-admin, wp-includes, wp-content)755
All normal files (.php, .js, .css, templates)644
wp-config.php600 or 640
wp-content/uploads directories755
wp-content/uploads files644

The wp-config.php file is a sensitive configuration file. It contains database credentials. You should change its permissions to 600 or 640. This prevents other users from reading it. The default permission of 666 makes the file world-writable. That is a security risk.

For a LAMP stack setup, you follow a similar process. First, set ownership to the Apache user. On Ubuntu, that user is www-data. Use sudo chown -R www-data:www-data /var/www/html. Then set directory permissions to 755 and file permissions to 644. Use the find command with -exec chmod to apply these changes recursively. For writable directories like uploads, use 775 permissions. This gives the group write access while keeping the server secure.

Security Best Practices and Common Mistakes

The most common mistake is using 777 permissions. This gives everyone full read, write, and execute access. Attackers can modify your files. They can inject malicious code. Your server becomes vulnerable. Never use 777 in production.

The principle of least privilege guides your permission choices. You grant only the minimum permissions needed. This principle applies to all parts of your server.

Principle of Least Privilege in Permission Design

The principle is applied by granting only the minimal permissions necessary for a component to function. For example, instead of granting broad access, a specific URI permission is granted for a single read operation. This allows fine-grained, ad-hoc access control, reducing the attack surface. The same principle applies to web application file permissions: only grant the minimum read, write, and execute permissions required for the web server to serve files. This prevents unauthorized access to sensitive files.

Security misconfiguration is a major risk. The OWASP Top 10 2021 ranks it as the 5th most critical AppSec risk. Common permission misconfigurations include:

  • Default accounts and passwords still enabled
  • Files and directories unprotected
  • Directory listing enabled
  • Open cloud storage buckets
  • Poorly configured firewalls

You should audit your server regularly. Check for unprotected files. Disable directory listing. Use safe default permissions for all new files. Your secure configuration prevents many attacks.

You use the chmod command for changing permissions. For a directory, run chmod 755 directoryname. For a file, run chmod 644 filename. You can also use chmod -R for recursive changes. Be careful with recursive changes. You might accidentally make files executable that should not be.

Your linux system relies on proper permissions. The owner of a file has full control. Other users have limited access. This balance keeps your server secure. Your application code runs correctly. Your data stays protected.

Remember these rules: directories need 755, files need 644, and sensitive configuration files need 600 or 640. Apply these permissions consistently. Your server will run smoothly and securely.

When to Choose 755 vs. 644: A Practical Guide

Directories and Executable Files: Go with 755

Use 755 for every directory on your web server. Directories always need execute permission so you can open them. Without it, you cannot enter the folder or see any files inside. This rule works the same on all Linux systems. Your web server must go through each directory in the path to your content. If any folder lacks execute permission, the server shows a “Permission denied” error.

Executable files also need 755. Scripts, binaries, and program files require the execute bit to run. Your application code often has these executable parts. For example, a PHP script that handles form data needs execute permission. A CGI program that makes dynamic content also needs it. You set these permissions with the chmod command. Run chmod 755 on the directory or script to give the owner full control and others read plus execute access.

Static Content and Data Files: Stick with 644

Static files only need read permission. HTML pages, CSS stylesheets, JavaScript files, and images all belong here. Your web server reads these files and sends them to visitors. No execution happens during this step. Use 644 for all static content. This setup gives the owner write access and everyone else read access only.

Data files also go in the 644 group. Configuration files, text documents, and database backups contain info but no executable code. Giving execute permission to these files creates extra risk. A user could accidentally run a data file as a program. That mistake wastes resources and might expose sensitive data.

The decision rule is simple. If the item needs to run or be entered, use 755. If it only needs to be read, use 644. This quick check helps you set safe default permissions across your whole server. You protect your application from unwanted changes while keeping your web server working. This balanced approach keeps security strong without breaking your website. Remember that Linux file permissions directly affect your server’s stability. The owner of each file controls its fate. Choose wisely, and your server stays secure and reliable.

You now understand the difference. Use 755 for directories and executable scripts. Use 644 for static content like HTML and images. This simple rule keeps your web server running smoothly.

Your linux file permissions directly affect security. Never use 777. Apply the principle of least privilege instead. Audit your server today. Check each folder and file. Set directories to 755 and files to 644. Your application code stays protected. Your server remains secure.

Remember this rule: if it runs or opens, use 755. If it only needs read access, use 644. File permissions matter for every owner.

FAQ

Why does my web server return a “Permission denied” error?

Your web server needs execute permission on every folder in the path to your files. If any folder lacks this right, the server cannot go through it. Check your folder permissions first. Set folders to 755 using chmod. This fix solves most access errors.

Can I use 777 permissions for my application files?

No. Using 777 gives everyone full access to your files. Attackers can change your code or add harmful content. This practice creates big security risks. Use the principle of least privilege instead. Use 755 for folders and 644 for static files. Your server stays safe with these settings.

Do configuration files need execute permission?

Configuration files hold settings, not executable code. They need read permission only. Set them to 644 or stricter. For sensitive files like wp-config.php, use 600 or 640. This protects your database login info. Your application reads these files without running them. Your server stays secure.

How do I fix permission issues on my linux server?

First, find which files or folders cause problems. Check ownership with ls -l. Then apply the correct permissions. Use chmod 755 for folders and scripts. Use chmod 644 for static content. Test your web server after each change. This step-by-step method fixes most permission errors.

What happens if I remove execute permission from a directory?

You lose the ability to enter that directory. Even with read permission, you cannot reach files inside it. Your web server cannot serve content from that folder. Visitors see errors instead of your website. Always keep execute permission on directories. This rule applies across all linux systems.