Progress: 0/62 (0%)
⚙️ Changing File Permissions (chmod)
Changing File Permissions (chmod)
Changing permissions is like changing the locks or keys on your house rooms. You decide who can read, write, or enter. In Linux, the command for this is:
chmod [options] permissions filename
There are two main ways to set permissions:
Changing permissions is like changing the locks or keys on your house rooms. You decide who can read, write, or enter. In Linux, the command for this is:
chmod [options] permissions filename
There are two main ways to set permissions:
2.1 Symbolic Mode (letters like u, g, o, +, -, =)
Here, we describe exactly who (user/group/others) can do what (add, remove, set):
| Symbol | Meaning |
|---|---|
| u | user/owner |
| g | group |
| o | others |
| a | all (user + group + others) |
| + | add permission |
| - | remove permission |
| = | set exact permission |
Examples:
- Add execute for everyone
chmod a+x script.sh
Analogy: Give all keys to enter the script room.
- Remove write for group
chmod g-w file.txt
Analogy: Take away the ability for team members to edit the document.
- Set exact permissions for owner, group, others
Owner can read/write
Group can read
Others have no access
chmod u=rw, g=r, o= file.txt
2.2 Numeric (Octal) Mode
Permissions can also be expressed as numbers:
| Permission | Value |
|---|---|
| r | 4 |
| w | 2 |
| x | 1 |
| - | 0 |
Add the values for each category (user/group/others).
Order: user group others
Examples:
- chmod 755 file.txt
7 = 4+2+1 → user can read, write, execute
5 = 4+0+1 → group can read & execute
5 = 4+0+1 → others can read & execute
- chmod 644 file.txt
6 = 4+2 → user can read/write
4 → group can read
4 → others can read
2.3 Quick Tips
- chmod +x file.sh → make a script executable
- chmod -R 700 folder/ → recursively lock down a folder so only you can access
Real-life analogy
If you want, the next topic will be Topic 3: Changing Ownership (chown), which is like changing the owner of a house or room.