A deep dive into managing Linux file permissions, ownership, and ACLs¶
1. Numeric (Octal) Permission Breakdown¶
Permissions are represented by a 3-digit (or 4-digit) octal number. Each digit is the sum of the permissions for Owner (u), Group (g), and Others (o).
Permission Values¶
- 4: Read (
r) - Ability to view file contents or list directory contents. - 2: Write (
w) - Ability to modify file contents or add/remove files in a directory. - 1: Execute (
x) - Ability to run a file as a program or enter a directory (cd). - 0: No permission (
-)
2. Symbolic Permission Notation¶
Instead of numbers, permissions can be modified using letters to add (+), remove (-), or exactly set (=) access.
Targets¶
- u: User (Owner)
- g: Group
- o: Others
- a: All (User, Group, and Others)
Examples of Symbolic Modifications¶
Add execute permission for the owner:
Remove write permission for group and others:
Set exact permissions (read/write for owner, read-only for group/others):
3. Special Permissions (SUID, SGID, and Sticky Bit)¶
Special bits alter the default execution or ownership behavior.
SUID (Set Owner User ID)¶
- Numeric:
4000(e.g.,4755) - Symbolic:
u+s - Function: Executes the file with the privileges of the file's owner (commonly root), not the user running it (e.g.,
/usr/bin/passwd).
SGID (Set Group ID)¶
- Numeric:
2000(e.g.,2755) - Symbolic:
g+s - Function: On a file, runs it with group privileges. On a directory, forces all newly created files within it to inherit the directory's group ownership rather than the creator's primary group.
Sticky Bit¶
- Numeric:
1000(e.g.,1777) - Symbolic:
+t - Function: Used on shared directories (
/tmp). Prevents users from deleting or renaming files they do not own, even if they have write access to the directory.
4. Comprehensive Numeric Configuration Matrix¶
Common Production & Desktop Permissions¶
777 (rwxrwxrwx)
- Read, write, and execute for everyone. (Dangerous for sensitive files).
755 (rwxr-xr-x)
- Owner has full access; group and others have read and execute access. (Standard for directories and executable scripts).
700 (rwx------)
- Owner has full access; group and others have no access. (Standard for private directories like
~/.ssh).
644 (rw-r--r--)
- Owner can read and write; group and others can only read. (Standard for configuration files and documents).
600 (rw-------)
- Owner can read and write; group and others have no access. (Standard for private files like SSH private keys).
5. Changing Permissions and Ownership Commands¶
Modify file or directory permissions recursively.
Change file owner and group.
Change file owner recursively.
View current permissions, ownership, and hidden files.
6. Access Control Lists (ACLs)¶
Standard permissions only allow one owner and one group. ACLs permit assigning permissions to specific additional users or groups.
View current ACLs on a file or directory.
Modify (add/change) an ACL to give a specific user read and write access.
Remove a specific user's ACL entry.
Remove all ACLs from a file.
7. Extended File Attributes (Immutable Files)¶
Attributes sit below standard permissions and can restrict root users. Highly relevant for protecting critical system files or BTRFS subvolume roots.
Make a file immutable (cannot be deleted, renamed, or modified by anyone, including root).
Remove the immutable attribute.
List extended attributes on a file.
8. SELinux Security Contexts¶
For systems enforcing SELinux, standard permissions are evaluated first, followed by SELinux policies.
List files with their SELinux security contexts.
Restore the default SELinux context for a file based on system policy (useful after moving files).
Change a file's SELinux context type manually.