Question
A Linux administrator wants to add a user to the Docker group without changing their primary group. Which of the following commands should the administrator use to complete this task?
- A. sudo groupmod docker user
- B. sudo usermod -g docker user
- C. sudo usermod -aG docker user Correct
- D. sudo groupmod -G docker user
Explanation
usermod -aG docker user adds docker to the user's supplementary groups and keeps the groups the user already has, because -a appends to the list given with -G. usermod -g would change the user's primary group, which is what the administrator wants to avoid. groupmod changes the properties of a group, not a user's memberships, and it has no -G option for this.