chmod
Change file mode bits and access permissions (read, write, execute) for owner, group, and others.
Common Options & Flags
| Option / Flag | Description |
|---|---|
| -R, --recursive | Change files and directories recursively |
| -v, --verbose | Output a diagnostic message for every file processed |
| -c, --changes | Like verbose but report only when a change is made |
| --reference=RFILE | Use RFILE permissions instead of mode values |
Practical Command Examples
Sets Owner: read/write (6), Group: read-only (4), Others: read-only (4).
Sets Owner: read/write/execute (7), Group & Others: read/execute (5).
Adds execute permission specifically for the file owner.
Recursively sets permissions on directory tree.
Production Real-World Use Case
Hardening web server document roots (e.g. Nginx/Apache) so script files are non-writable by public web users while remaining readable by www-data.
Common Mistakes
- ✕Running chmod -R 777 on web roots (exposes write access to malicious users).
- ✕Forgetting execute bit on shell scripts or directories (prevents cd navigation).
Security Considerations
Never assign 777 permissions in production. Always principle of least privilege (644 for files, 755/750 for directories).
Watch Command Video Breakdown
Interactive Calculator Available
Use our visual tool for instant calculation.
