chmod means:
change mode
It is used to change file or directory permissions.
Main permissions:
| Permission | Meaning | Value |
|---|---|---|
| r | Read | 4 |
| w | Write | 2 |
| x | Execute | 1 |
1. Symbolic Method
Uses:
- u = user/owner
- g = group
- o = others
- a = all
Operators:
- + add permission
- remove permission
- = set exact permission
Add execute permission
chmod u+x script.sh
Meaning:
- owner gets execute permission
Example:
Before:
- rw-r--r--
After:
- rwxr--r--
Add read for group
chmod g+r file.txt
Remove write
chmod o-w file.txt
Give all execute permission
chmod a+x app.sh
Set exact permission
chmod u=rw,g=r,o= file.txt
Meaning:
- owner = read + write
- group = read
- others = no permission
2. Octal Method
Uses numbers:
| Permission | Value |
|---|---|
| r | 4 |
| w | 2 |
| x | 1 |
Add values:
Example:
rwx = 4+2+1 = 7
rw- = 4+2 = 6
r-x = 4+1 = 5
r-- = 4
Common octal permissions
| Number | Meaning |
|---|---|
| 777 | everyone full access |
| 755 | owner full, others read+execute |
| 644 | owner read+write, others read |
| 600 | owner only |
| 700 | owner full only |
Example
chmod 755 script.sh
Meaning:
Owner = rwx = 7
Group = r-x = 5
Others = r-x = 5
Another Example
chmod 644 notes.txt
Result:
- rw-r--r--
Real-World Examples
Make script executable
chmod +x deploy.sh
Run:
./deploy.sh
SSH private key security
chmod 600 ~/.ssh/id_rsa
Only owner can read/write.
Website folder
chmod 755 /var/www/html
Owner can edit, others can read.
Check permissions
ls -l
Example:
- rwxr-xr-x deploy.sh
Top comments (0)