CompTIA Linux+ (XK0-006)Services and User ManagementMedium
A developer is working on a Linux system and wants to ensure that a specific Python script, `/opt/scripts/data_processor.py`, executes with the permissions of the `datauser` group, even when run by other users. The script itself should not be writable by anyone other than its owner. Which `chmod` command should be used?
- Asudo chmod 2755 /opt/scripts/data_processor.py
- Bsudo chmod 6755 /opt/scripts/data_processor.py
- Csudo chmod 4755 /opt/scripts/data_processor.py
- Dsudo chmod 0775 /opt/scripts/data_processor.py
Show answer & explanationAnswer & explanation
Correct answer: A. sudo chmod 2755 /opt/scripts/data_processor.py
The `2` in the octal permission `2755` sets the SGID bit. This ensures that when the script is executed, it runs with the effective group ID of the file's group owner (`datauser` in this context), while `755` provides rwx for owner, rx for group, and rx for others, fulfilling the 'not writable by anyone other than its owner' requirement.
Why the other options are wrong
- B. `6755` sets both SUID and SGID bits, which is not what is requested (only group permissions are needed).
- C. `4755` sets the SUID bit, causing the script to run with the owner's permissions, not the group's.
- D. `0775` does not set the SGID bit; it only sets standard permissions.
SGID (Set Group ID) on files
The SGID permission bit, when set on an executable file, causes the process to run with the effective group ID of the file's group owner, rather than the primary group ID of the user executing it.
- Represented by `s` in the group execute position (`rws` or `r-s`).
- Octal value is `2` in the special permissions digit.
- Useful for shared applications or scripts requiring specific group access.
Memory trick: Special bits grant super powers to files.