Understanding Octal Permissions in Linux
Linux file permissions are often represented in two ways:
1. Symbolic notation → e.g., rwxr-xr--
2. Octal (numeric) notation → e.g., 754
Octal notation is simply a numeric shorthand for symbolic permissions.
1. Symbolic Permissions (The Long Form)
Linux permissions operate on three categories:
Example:
rwx r-x r--
Breaks down as:
2. The Numeric (Octal) System
For each of the permissions (r, w, x), Linux assigns a numeric value:
To convert symbolic to octal, add the values:
Examples:
- rwx → 4 + 2 + 1 → 7
- rw- → 4 + 2 + 0 → 6
- r-x → 4 + 0 + 1 → 5
- r-- → 4 + 0 + 0 → 4
- --- → 0 + 0 + 0 → 0
3. Putting It Together: Octal Notation
A full permission set requires 3 octal digits (user, group, others):
- (user)(group)(others)
Example:
- 754
Breaks down to:
- 7 = rwx (owner)
- 5 = r-x (group)
- 4 = r-- (others)
Symbolically:
Rwx r-x r--
4. Common Octal Permission Values
For Files
For Directories
5. Special Bits (Setuid, Setgid, Sticky Bit)
Sometimes you’ll see 4 digits (e.g., 4755).
The first digit is for special permissions:
Examples:
- 4755 → setuid bit + rwx r-x r-x
- 1777 → sticky bit + rwx rwx rwx (used on /tmp)
6. Setting Permissions with chmod
Use octal notation directly:
1. chmod 754 filename
2. chmod 700 private_script.sh
3. chmod 1777 /shared/tmp
7. Why Use Octal Instead of Symbolic?
Octal is:
- faster (chmod 755 file)
- unambiguous
- very common in scripts and system admin work
Symbolic mode is better for tweaking permissions:
1. chmod g+w file
2. chmod o-rwx file
But octal mode is perfect for resetting permissions.
No comments:
Post a Comment