Modifying Permissions with Chmod: A Developer's Linux Guide
Learn how to use chmod to modify Linux file permissions. Master symbolic and numeric modes to secure your server project files with precision.

Previously in this course, we covered File Permissions Fundamentals: Decoding Linux Access Controls, where you learned how to interpret the rwx strings returned by ls -l. Now, we move from observation to action: you’ll learn how to modify those permissions using chmod to harden your server environment.
The chmod (change mode) command is your primary tool for defining who can read, write, or execute files. Without it, you cannot restrict access to sensitive configuration files or enable scripts to run as executables.
Changing Permissions with Symbolic Mode
Symbolic mode uses letters to represent the user (u), group (g), others (o), and all (a), combined with operators to add (+), remove (-), or set (=) permissions. This is often more readable than numbers.
To change permissions for the owner, group, or others, follow this syntax: chmod [who][operator][permission] [file].
For example, if you have a shell script in your web server project that isn't currently executable, you can grant execute permissions to the owner like this:
Bash# Grant execute permission to the user (u) chmod u+x deploy.sh # Remove write permissions from everyone else chmod o-w config.json
Mastering Numeric Mode for Precise Control

Numeric mode is the "pro" way to set permissions. It uses a three-digit octal value (e.g., 755), where each digit represents the sum of permissions for the owner, group, and others respectively.
- 4 = Read (r)
- 2 = Write (w)
- 1 = Execute (x)
- 0 = No permission
By adding these numbers, you create the permission set. 7 (4+2+1) means full access, while 5 (4+0+1) means read and execute.
| Numeric Mode | Meaning | Use Case |
|---|---|---|
600 | Owner read/write only | Sensitive config/SSH keys |
644 | Owner RW, others read | Standard web content files |
755 | Owner RWX, others RX | Directories and executable scripts |
To apply this to our project's configuration file:
Bash# Sets owner to RW, group to R, others to R chmod 644 config.json
Applying Recursive Permissions
When managing a web server, you often need to set permissions for an entire directory tree. Using the -R (recursive) flag allows you to apply changes to a directory and everything inside it.
Warning: Use this carefully. You rarely want to make every file in a directory executable.
Bash# Make all directories within /var/www/html searchable (755) # This is a common requirement for web server access chmod -R 755 /var/www/html/public
Hands-on Exercise: Securing Your Web Project
- Navigate to your project directory.
- Create a dummy secret file:
touch secret_config.env. - Set the permissions so only you can read and write it (
600). - Verify the change with
ls -l secret_config.env. The string should look like-rw-------. - Create a
scriptsdirectory and ensure your owner has full control while others have none (700).
Common Pitfalls

- The "Everything is 777" Trap: Beginners often run
chmod -R 777to fix "Permission Denied" errors. This is a massive security risk. It allows any user on the system to modify or delete your files. Always use the principle of least privilege (give only the access required). - Directory Execution: Directories require the "execute" (x) permission to be traversed. If you remove
xfrom a directory, you cannotcdinto it, even if you have read access. - Recursive Overkill: Be careful running
chmod -Ron files. If you change a file's permission to777because you meant to change a directory, you've left that file vulnerable to modification by any malicious actor.
FAQ
Q: What is the default permission for new files?
A: This is controlled by the umask setting, which subtracts permissions from the system default. We will cover this in detail in a future lesson on environment configurations.
Q: Can I change permissions for a file I don't own?
A: Only the owner of the file or the root user can change permissions using chmod. If you are not the owner, you will need sudo.
Q: Is 755 always the best for directories?
A: It is standard for web servers because it allows the server process to enter the directory and read the files. However, if a directory contains sensitive user data, you should use 700 or 750.
Recap

You’ve mastered chmod by using symbolic modes for quick changes and numeric modes for precision. You also learned how to handle directory structures recursively and, most importantly, why you should avoid 777 at all costs. Keeping your config files set to 600 is your first real step toward a hardened production environment.
Up next: We will look at changing file ownership with chown to ensure your web server process only has access to the files it absolutely needs.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Custom WordPress Plugin Development
Custom WordPress & WooCommerce plugins built to standard — by the developer behind a plugin with 5,000+ active installs and a SaaS with 10,000+ users.

