#readwise
# Linux Fundamentals - Permission Management

## Metadata
- Author: [[Hack The Box]]
- Full Title: Linux Fundamentals - Permission Management
- URL: https://academy.hackthebox.com/module/18/section/83
## Summary
Linux permissions control access to files and directories, acting like keys for users and groups. Each file has an owner and a group, with specific permissions for reading, writing, and executing. Users need execute permissions to navigate directories, while they must have appropriate permissions to modify files. Special permissions like SUID, SGID, and the sticky bit enhance security for shared files and directories.
## Highlights
In Linux, permissions are like keys that control access to files and directories. These permissions are assigned to both users and groups, much like keys being distributed to specific individuals and teams within an organization. Each user can belong to multiple groups, and being part of a group grants additional access rights, allowing users to perform specific actions on files and directories.
Every file and directory has an owner (a user) and is associated with a group. The permissions for these files are defined for both the owner and the group, determining what actions—like reading, writing, or executing—are allowed. When you create a new file or directory, it automatically becomes "yours" and is associated with the group you belong to, similar to how a project within a company might default to your team’s oversight.
In essence, Linux permissions act like a set of rules or keys that dictate who can access or modify certain resources, ensuring security and proper collaboration across the system. ([View Highlight](https://read.readwise.io/read/01jm7s4dhganvt7vt8p58ejjwr))
---
When a user wants to access the contents of a Linux directory, it's similar to unlocking a door before stepping inside. To "traverse" or navigate into a directory, the user must first have the right key—this key is the `execute` permission on the directory. Without it, even if the contents of the directory are visible to the user, they won't be able to enter or move through it.
In other words, having `execute` permissions on a directory is like having permission to walk through a hallway to access the rooms inside. It doesn't allow you to see or modify what's inside, but it does grant you the ability to step inside and explore the directory's structure. Without this permission, the user cannot access the directory's contents and will instead be presented with a “`Permission Denied`" error message. ([View Highlight](https://read.readwise.io/read/01jm7s51njdgnbfp7ez2183ckz))
---
In addition to standard user and group permissions, Linux allows us to configure special permissions on files through the Set User ID (`SUID`) and Set Group ID (`SGID`) bits. These bits function like temporary access passes, enabling users to run certain programs with the privileges of another user or group. For example, administrators can use `SUID` or `SGID` to grant users elevated rights for specific applications, allowing tasks to be performed with the necessary permissions, even if the user themselves doesn’t normally have them.
The presence of these permissions is indicated by an `s` in place of the usual `x` in the file's permission set. When a program with the SUID or SGID bit set is executed, it runs with the permissions of the file's owner or group, rather than the user who launched it. This can be useful for certain system tasks but also introduces potential security risks if not used carefully. ([View Highlight](https://read.readwise.io/read/01jm7scgf5w76brc965mbka3e2))
---
One common risk is when administrators, unfamiliar with an application's full functionality, assign `SUID` or `SGID` bits indiscriminately. For example, if the `SUID` bit is applied to a program like `journalctl`, which includes a function to launch a shell from within its interface, any user running this program could execute a shell as root. This grants them complete control over the system, presenting a significant security vulnerability. ([View Highlight](https://read.readwise.io/read/01jm7sdjzbwrvrv5aj9ya2g797))
---
Sticky bits in Linux are like locks on files within shared spaces. When set on a directory, the sticky bit adds an extra layer of security, ensuring that only certain individuals can modify or delete files, even if others have access to the directory. ... In a shared directory, this means only the file's owner, the directory's owner, or the root user (the system administrator) can delete or rename files. Other users can still access the directory but can’t modify files they don’t own.
This feature is especially useful in shared environments, like public directories, where multiple users are working together. By setting the sticky bit, you ensure that important files aren’t accidentally or maliciously altered by someone who shouldn’t have the authority to do so, adding an important safeguard to collaborative workspaces.
---