RHCSA User and Group Management Questions and Answers — Questions and Answers
Question 1: A system administrator needs to add an existing user, 'jsmith', to the supplementary 'developers' group without removing them from any other groups they are currently a member of. Which of the following commands will accomplish this task correctly?
- usermod -G developers jsmith
- usermod -g developers jsmith
- usermod -aG developers jsmith (Correct answer)
- useradd -G developers jsmith
Correct answer: usermod -aG developers jsmith
The `usermod` command is used to modify an existing user account. The `-a` (append) option is crucial; it adds the user to the supplementary group(s) specified with the `-G` option without removing them from their current groups. Using `-G` alone would replace the user's entire list of supplementary groups with the new one. The `-g` option modifies the user's primary group, not supplementary groups. The `useradd` command is for creating new users, not modifying existing ones.
Question 2: As a system administrator, you want to ensure that all newly created user accounts automatically have a default `.bash_profile` and a `README.txt` file in their home directory. Where should you place these template files?
- /etc/default/useradd
- /etc/skel (Correct answer)
- /etc/login.defs
- /home
Correct answer: /etc/skel
The `/etc/skel` directory serves as a skeleton directory. Files and directories within `/etc/skel` are automatically copied to a new user's home directory when the account is created with the `useradd` command. `/etc/default/useradd` and `/etc/login.defs` contain default settings for user creation but not file templates. `/home` is the parent directory for user home directories but does not serve as a template.
Question 3: A user, 'pjenkins', has their primary group set incorrectly. The administrator needs to change the user's primary group to 'sales'. Which command should be used?
- usermod -G sales pjenkins
- chgrp sales /home/pjenkins
- usermod -aG sales pjenkins
- usermod -g sales pjenkins (Correct answer)
Correct answer: usermod -g sales pjenkins
The `usermod` command with the lowercase `-g` option is used to change a user's primary group ID (GID). The uppercase `-G` option is for managing supplementary (secondary) groups. `chgrp` changes the group ownership of files and directories, but not the user's primary group attribute in the `/etc/passwd` file. The `-aG` options are for appending supplementary groups.
Question 4: Which of the following commands would a system administrator use to view the most recent login times for all users on the system?
- who
- users
- lastlog (Correct answer)
- id
Correct answer: lastlog
The `lastlog` command formats and prints the contents of the `/var/log/lastlog` file, which records the most recent login for each user. The `who` command shows who is currently logged on. The `users` command lists the usernames of currently logged-in users. The `id` command displays user and group ID information for a specified user, not login times.
Question 5: A user account named 'tempuser' is no longer needed, and a sysadmin has been tasked with removing the account along with its home directory and mail spool. Which command will achieve this?
- userdel tempuser
- usermod -L tempuser
- userdel -r tempuser (Correct answer)
- rm -rf /home/tempuser
Correct answer: userdel -r tempuser
The `userdel` command is used to delete a user account. By default, it does not remove the user's home directory. The `-r` option must be used to also remove the user's home directory and mail spool. `usermod -L` would lock the account, not delete it. Simply using `rm -rf` on the home directory would leave the user account entry in files like `/etc/passwd` and `/etc/shadow`.
Question 6: What is the primary purpose of the `/etc/group` file in a Linux system?
- To store user password hashes and aging information.
- To define default settings for new user creation.
- To list all existing user accounts and their primary attributes.
- To define group names, GIDs, and list the members of each group. (Correct answer)
Correct answer: To define group names, GIDs, and list the members of each group.
The `/etc/group` file contains essential information about the groups on the system. Each line defines a group, including its name, Group ID (GID), and a comma-separated list of its members. User password hashes are stored in `/etc/shadow`. Default user creation settings are in `/etc/login.defs` and `/etc/default/useradd`. User account attributes are primarily stored in `/etc/passwd`.
A system administrator needs to add an existing user, 'jsmith', to the supplementary 'developers' group without removing them from any other groups they are currently a member of.
Which of the following commands will accomplish this task correctly?