CompTIA Linux+ (XK0-006)Services and User ManagementHard
A system administrator is setting up a shared directory, `/data/projects`, where multiple users from the `devteam` group will collaborate. All new files and subdirectories created within `/data/projects` by any `devteam` member should automatically inherit the `devteam` group ownership. The directory also needs to be writable by `devteam` members and readable by others, but not writable by others. Which `chmod` command should be applied to `/data/projects`?
- Asudo chmod 2775 /data/projects
- Bsudo chmod 2770 /data/projects
- Csudo chmod 1775 /data/projects
- Dsudo chmod 775 /data/projects
Show answer & explanationAnswer & explanation
Correct answer: A. sudo chmod 2775 /data/projects
The `2` in `2775` sets the SGID bit on the directory. When SGID is set on a directory, new files and subdirectories created within it automatically inherit the group ownership of the parent directory (`devteam`), fulfilling the primary requirement. `775` provides rwx for owner, rwx for group, and rx for others, which matches the remaining permission requirements.
Why the other options are wrong
- B. `2770` correctly sets the SGID bit and gives rwx to owner and group, but it denies all access to others, which contradicts the requirement for others to have read access.
- C. `1775` sets the sticky bit, which prevents users from deleting or renaming files in the directory unless they own them, but it does not ensure group inheritance.
- D. `775` sets standard permissions but does not enable SGID for group inheritance.
SGID on Directories
When the SGID (Set Group ID) permission bit is set on a directory, any new files or subdirectories created within that directory will automatically inherit the group ownership of the parent directory.
- Represented by `s` in the group execute position (e.g., `drwxrwsr-x`).
- Octal value is `2` in the special permissions digit.
- Crucial for collaborative directories where consistent group ownership is needed.
Memory trick: Special dir bits make group inheritance easy.