Question

Difficulty: HardmacOS and Linux Operating System Features and Tools

A Linux technician is resolving permission issues on a web server. A web service running under the `www-data` group requires read and write access to all existing files and subdirectories within `/var/www/html/uploads`. Currently, files inside the directory are owned by `ubuntu:ubuntu` with permissions set to `-rw-r--r--` (`644`), and subdirectories have permissions `drwxr-xr-x` (`755`). The technician must grant group write access to `www-data` across all nested files and subdirectories without altering file user ownership, breaking directory traversal capabilities, or granting world-write permissions. Which of the following command combinations should the technician execute?

  1. chown -R :www-data /var/www/html/uploads && chmod -R g+w /var/www/html/uploadsAnswer
  2. B
    chmod -R www-data /var/www/html/uploads && chown -R 775 /var/www/html/uploads
  3. C
    chown -R www-data: /var/www/html/uploads && chmod -R 664 /var/www/html/uploads
  4. D
    chgrp -u www-data /var/www/html/uploads && chmod -R 777 /var/www/html/uploads

Answer

The technician should run `chown -R :www-data /var/www/html/uploads && chmod -R g+w /var/www/html/uploads`.
The correct command combination uses `chown -R :www-data` to recursively update group ownership to `www-data` while preserving user ownership (`ubuntu`). It then uses `chmod -R g+w` to recursively append write permissions for the group, turning existing `644` files into `664` and `755` directories into `775`. This grants the web service read and write privileges without removing the directory execute (`x`) bit necessary for file traversal.

Step-by-Step Solution

1
Identify group ownership requirements
Group ownership must be changed to `www-data` across all files and subdirectories recursively.
Using `chown -R :www-data` modifies the group owner without changing the existing user owner (`ubuntu`).
2
Identify access permission requirements
Write access (`+w`) must be added for the group across all files and subdirectories recursively.
Symbolic notation `chmod -R g+w` adds group write privileges without removing existing execute (`+x`) permissions on directories.
3
Validate security and directory traversal boundaries
Files become `664` (`rw-rw-r--`) and directories become `775` (`rwxrwxr-x`).
This preserves directory execution/traversal for the group while preventing world-write (`777`) security risks.

Key Concept

Linux File Ownership and Symbolic/Absolute Permissions Management
Rate this question