LFCS User and Group Management Questions and Answers — Questions and Answers
Question 1: A system administrator needs to add an existing user, 'testuser', to an existing supplementary group called 'developers'. Which of the following commands will achieve this without removing the user from their current supplementary groups?
- usermod -G developers testuser
- usermod -g developers testuser
- usermod -aG developers testuser (Correct answer)
- useradd -G developers testuser
Correct answer: usermod -aG developers testuser
The `usermod -aG` command is used to modify a user's group membership. The `-a` (append) flag is crucial as it adds the user to the specified group(s) without removing them from their existing supplementary groups. The `-G` flag specifies the supplementary group(s).
Question 2: Which file should be modified to set the default password aging policies, such as `PASS_MAX_DAYS`, for all newly created users on a Linux system?
- /etc/passwd
- /etc/shadow
- /etc/default/useradd
- /etc/login.defs (Correct answer)
Correct answer: /etc/login.defs
The `/etc/login.defs` file contains system-wide configuration for user and group management tools. It is the correct place to define default password aging policies like `PASS_MAX_DAYS`, `PASS_MIN_DAYS`, and `PASS_WARN_AGE` that will be applied to all new user accounts created with `useradd`.
Question 3: A temporary user account named 'contractor' needs to be created, and it must automatically be disabled on a specific date. Which command correctly creates the user with an expiration date of December 31, 2026?
- useradd -e 2026-12-31 contractor (Correct answer)
- chage -E 2026-12-31 contractor
- usermod -L 2026-12-31 contractor
- useradd --disable-date 2026-12-31 contractor
Correct answer: useradd -e 2026-12-31 contractor
The `useradd` command is used to create new users. The `-e` or `--expiredate` option allows you to specify a date on which the user account will be disabled. The date format is YYYY-MM-DD.
Question 4: A user, 'jdoe', reports that they cannot access files owned by the 'editors' group. You need to change 'jdoe's' primary group to 'editors'. Which command accomplishes this?
- usermod -G editors jdoe
- usermod -g editors jdoe (Correct answer)
- groupmod -n editors jdoe
- newgrp editors jdoe
Correct answer: usermod -g editors jdoe
The `usermod` command is used to modify user account details. The `-g` (lowercase) option specifically changes the user's primary group ID (GID). The group 'editors' must already exist.
Question 5: As a system administrator, you need to create a new group named 'auditors' with a specific Group ID (GID) of 2005. Which of the following commands is the correct way to do this?
- groupadd -i 2005 auditors
- addgroup --gid 2005 auditors
- groupadd -g 2005 auditors (Correct answer)
- newgroup -g 2005 auditors
Correct answer: groupadd -g 2005 auditors
The `groupadd` command is the standard utility for creating new groups. The `-g` or `--gid` option is used to specify the numerical Group ID (GID) for the new group.
Question 6: After creating a new user, you are tasked with setting their password to expire in 90 days, warning them 14 days before it expires, and locking the account 7 days after it expires. Which command is best suited for modifying all these password aging attributes for an existing user?
- useradd
- usermod
- passwd
- chage (Correct answer)
Correct answer: chage
The `chage` (change age) command is specifically designed to modify user password expiry information. It can be used to set the maximum number of days between password changes (`-M`), the warning period (`-W`), and the inactive period (`-I`) after expiration before the account is locked.
A system administrator needs to add an existing user, 'testuser', to an existing supplementary group called 'developers'.
Which of the following commands will achieve this without removing the user from their current supplementary groups?