Permissions & SecurityCLI Reference
$chmod
Change file access permission mode bits for owner, group, and other users.
Syntax DefinitionPOSIX standard
chmod [OPTIONS] MODE[,MODE]... FILE...Try `chmod` Live in Interactive Sandbox
Zero-install client simulation with real-time feedback.
bash — terminal
AST Sandbox (Free)
Overview & How chmod Works
`chmod` (Change Mode) manages file and directory permissions in Linux. Every file has read (`r=4`), write (`w=2`), and execute (`x=1`) permissions for three classes: User (Owner), Group, and Others. Permissions can be set using 3-digit octal notation (e.g., `755` or `644`) or symbolic notation (e.g., `u+x`, `g-w`, `o=r`).
Common Flags & Command Options
| Flag / Option | Description |
|---|---|
| 755 | rwxr-xr-x: Owner has full control; group and others can read and execute. |
| 644 | rw-r--r--: Owner can read and write; group and others can read only. |
| 700 | rwx------: Owner has full control; no access for anyone else. |
| -R | Recursively change file permissions on all subdirectories and files. |
| +x | Make a script or binary file executable for all users. |
Practical Real-World Examples
Example #1Make a bash script executable
chmod +x /home/user/projects/demo.sh && ls -l /home/user/projects/demo.shAdds execute permissions to demo.sh and verifies the updated mode bits.
Sample Output:
-rwxr-xr-x 1 user user 180 Aug 28 12:10 demo.shExample #2Set standard web file permissions (644)
chmod 644 /var/log/syslogGrants read/write to owner and read-only to group and others.
Common Errors & Troubleshooting
chmod: changing permissions of ...: Operation not permitted
Cause: You do not own the file and lack root privileges.
Solution: Use `sudo chmod 755 [file]` or switch to the file owner account.
Frequently Asked Questions
What do the numbers in chmod 755 represent?
Each digit represents permissions for Owner, Group, and Others. 7 is 4(read)+2(write)+1(execute), while 5 is 4(read)+1(execute).