The Linux security model is built upon strict permission attributes assigned to every file and directory. Misconfigured permissions can lead to web server errors like 403 Forbidden or Permission Denied, while overly permissive settings introduce critical security vulnerabilities. In this guide, we explore the Linux permission architecture alongside the practical usage of chmod and chown.
Permission Structure and User Scopes
Every file in Linux regulates access across three distinct user categories: Owner (User), assigned Group, and everyone else (Others).
| Permission | Symbol | Numeric Value | Meaning for Files / Directories |
|---|---|---|---|
| Read | r | 4 | Read file contents or list items inside a directory. |
| Write | w | 2 | Modify content, delete, or create new files in a directory. |
| Execute | x | 1 | Execute binary/script or enter into a directory path. |
Modifying Permissions with chmod
The chmod (Change Mode) command sets permissions by summing numeric octal values (e.g., 4 + 2 + 1 = 7 for full permissions).
- chmod 644 file.txt: Owner has read/write (6), group and others have read-only (4). Default for web assets.
- chmod 755 script.sh: Owner has full access (7), others can read and execute (5). Standard for directories and scripts.
- chmod 700 key.pem: Exclusively accessible by the owner with zero access for others. Mandatory for private SSH keys.
Changing Ownership with chown
The chown (Change Owner) command delegates file or folder ownership to specific system users and groups.
# 1. Change file owner to 'www-data' (standard web server user) sudo chown www-data index.php # 2. Change both owner and group simultaneously sudo chown www-data:www-data index.php # 3. Recursively change ownership for an entire directory tree (-R) sudo chown -R www-data:www-data /var/www/html/
Golden Rule of Permission Security
Never run chmod 777 in a production environment. Granting full read, write, and execute permissions to all users allows attackers to alter files and inject arbitrary code. Always apply the Principle of Least Privilege to safeguard your servers.