XK0-004 · Question #345
An administrator is adding an existing user named `'buddy'' to the Apache group. Which of the following should the administrator perform to accomplish this task?
The correct answer is B. ssermod -g apche buddy. Modifying an existing user's group membership requires usermod, not useradd. The correct command is sudo usermod -g apache buddy.
Question
An administrator is adding an existing user named `'buddy'' to the Apache group. Which of the following should the administrator perform to accomplish this task?
Options
- Asseradd -g apache buddy
- Bssermod -g apche buddy
- Csudo useradd -g apache buddy
- Dsudo usermod -g apachebuddy
How the community answered
(39 responses)- A3% (1)
- B92% (36)
- C5% (2)
Why each option
Modifying an existing user's group membership requires usermod, not useradd. The correct command is sudo usermod -g apache buddy.
useradd is used exclusively for creating new user accounts, not modifying existing ones, and would fail or conflict if the user buddy already exists.
usermod is the correct command for modifying properties of an existing user account, including group membership. The -g flag sets the user's primary group, so the intended command sudo usermod -g apache buddy correctly reassigns buddy's primary group to apache without creating a new account or causing conflicts.
sudo useradd -g apache buddy attempts to create a brand new user named buddy rather than modifying the existing account, which would produce an error since the user already exists.
sudo usermod -g apachebuddy is missing a space between the group name and username, causing the shell to parse 'apachebuddy' as the group argument, referencing a nonexistent group.
Concept tested: Modifying existing user group membership with usermod
Source: https://man7.org/linux/man-pages/man8/usermod.8.html
Topics
Community Discussion
No community discussion yet for this question.