CompTIA Linux+ (XK0-006)Services and User ManagementHard

A system administrator needs to grant the `webdevs` group read, write, and execute permissions to a specific directory `/var/www/html/projectA`, while ensuring that all files and subdirectories created within `projectA` by any member of `webdevs` automatically inherit the `webdevs` group ownership. Which two commands, executed consecutively, will achieve this?

  1. Achmod 2770 /var/www/html/projectA && chown :webdevs /var/www/html/projectA
  2. Bchmod g+rwx /var/www/html/projectA && chown :webdevs /var/www/html/projectA
  3. Cchmod g+rwx /var/www/html/projectA && chmod g+s /var/www/html/projectA
  4. Dchmod 770 /var/www/html/projectA && chgrp webdevs /var/www/html/projectA
Show answer & explanation

Correct answer: A. chmod 2770 /var/www/html/projectA && chown :webdevs /var/www/html/projectA

The `chmod 2770` command sets the permissions to `rwxrwx---` for owner and group, and importantly, sets the SGID bit (the '2' in `2770`). The SGID bit on a directory ensures that new files and subdirectories created within it inherit the parent directory's group ownership. The `chown :webdevs` command then sets the group ownership of the directory itself to `webdevs`.

Why the other options are wrong

  • B. This sets group permissions correctly, but does not set the SGID bit, so group ownership will not be inherited.
  • C. While `chmod g+s` sets the SGID bit, the initial `chmod g+rwx` is redundant if `g+s` is used, as `g+s` implies `g+x` and combines with other group permissions. The group ownership still needs to be set, which is missing here.
  • D. This sets the permissions, but `770` does not include the SGID bit. `chgrp` is synonymous with `chown :group` for changing group ownership.

SGID on Directories for Group Inheritance

The Set Group ID (SGID) bit on a directory forces all new files and subdirectories created within it to inherit the parent directory's group ownership.

  • Set with `chmod g+s` or `chmod 2xxx`.
  • Applies group ownership inheritance, not permissions.
  • Useful for shared directories among team members.

Memory trick: Group 'S'hares and 'G'ets 'ID'ea from parent.

More Services and User Management questions