Keep alice's existing supplementary groups and add docker.
Which command is appropriate?
usermod -aG GROUP USER appends a supplementary group; -G without -a replaces the existing list.
Detailed explanation
usermod -G docker aliceIncorrect. -G alone replaces the supplementary-group list with docker.
Incorrect. -G alone replaces the supplementary-group list with docker.
usermod -g docker aliceIncorrect. -g changes the primary group.
Incorrect. -g changes the primary group.
usermod -aG docker aliceCorrect. -aG appends docker while preserving existing supplementary groups.
Correct. -aG appends docker while preserving existing supplementary groups.
groupmod -a docker aliceIncorrect. groupmod is not the user-membership command.
Incorrect. groupmod is not the user-membership command.
Try it yourself
An example you can run in a temporary verification environment.
usermod --help 2>&1 | grep -E -- '--append|--groups'Expected result
-a/--appendと-G/--groupsの説明Key points
- -a means append
- Use with -G
- -G alone replaces
Notes
- Environment: shadow-utils usermod / help読取のみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.