Permissions & Ownership
Linux is a multi-user system where security is enforced through a robust permission model. Every file and directory is owned by a specific User and Group.
1. Anatomy of ls -l
When you run ls -l, the first 10 characters tell you everything about the file's permissions.
- rwx r-x r--
| | | |
| | | +-- Others (r--)
| | +------ Group (r-x)
| +---------- Owner / User (rwx)
+------------- File Type (- = Regular, d = Directory)2. Permission Notation
Permissions can be represented in two ways: Symbolic (letters) and Numeric (octal).
Numeric (Octal) Reference
Values are additive: Read (4) + Write (2) + Execute (1).
| Value | Symbolic | Meaning |
|---|---|---|
| 7 | rwx | Full access (4+2+1) |
| 6 | rw- | Read and Write (4+2) |
| 5 | r-x | Read and Execute (4+1) |
| 4 | r-- | Read only |
| 0 | --- | No permissions |
3. Modifying Permissions
chmod (Change Mode)
- Symbolic:
chmod u+x file.sh(Give owner execute permission). - Numeric:
chmod 755 file.sh(Owner: rwx, Group: r-x, Others: r-x).
chown & chgrp
chown: Change the owner (and optionally group).sudo chown john:admins app.log
chgrp: Change only the group.sudo chgrp developers config.json
umask
The umask command defines the default permissions for newly created files. It "masks" (subtracts) permissions from the maximum possible value.
[!TIP] Quick Recall If you see
755, think: "I have full control (7), everyone else can just see and run it (5)".