How chmod Works in Kali Linux
In Kali Linux (and all Linux systems), the chmod command is used to change file or directory permissions. It controls who can read, write, or execute a file.
Permission Basics
Each file has three types of permissions for three classes of users:
- Permissions:
r= readw= writex= execute
- User classes:
u= user (owner)g= groupo= othersa= all
Example permission string
-rwxr-xr--
This means:
- Owner: read, write, execute (
rwx) - Group: read, execute (
r-x) - Others: read only (
r--)
Syntax
chmod [options] mode file
Two Ways to Set Permissions
1) Symbolic Mode
Use letters (u, g, o, a) and operators (+, -, =):
+→ add permission-→ remove permission=→ set exact permission
chmod u+x script.sh # add execute for owner
chmod g-w file.txt # remove write for group
chmod o=r file.txt # set others to read only
chmod a+r file.txt # everyone can read
2) Octal (Numeric) Mode
Numbers represent permissions where r=4, w=2, x=1. Add them for each class.
| Number | Permission |
|---|---|
| 7 | rwx |
| 6 | rw- |
| 5 | r-x |
| 4 | r-- |
| 3 | -wx |
| 2 | -w- |
| 1 | --x |
| 0 | --- |
chmod 755 script.sh # rwx for owner, r-x for group/others
chmod 644 file.txt # rw- for owner, r-- for group/others
chmod 700 secret.txt # rwx for owner only
Special Permissions
- 4 (setuid) → run program as file owner
- 2 (setgid) → run with group privileges
- 1 (sticky bit) → only owner can delete in shared directory
chmod 1777 /tmp # sticky bit set, common for /tmp
Summary
chmod changes permissions so you can control access to files and directories. You can use symbolic (u/g/o/a with + - =) or octal (numbers 0–7) methods. It’s critical for security, especially when setting execute rights on scripts or restricting sensitive files.