Add existing user kai to supplementary group docker.
Keep all current supplementary groups.
Which command is appropriate?
Use usermod with -aG. The -a append option is essential; without it, -G replaces the supplementary-group list.
Detailed explanation
usermod -aG docker kaiCorrect. -aG appends docker to the existing supplementary groups.
Correct. -aG appends docker to the existing supplementary groups.
usermod -G docker kaiIncorrect. -G alone replaces the existing list with docker.
Incorrect. -G alone replaces the existing list with docker.
usermod -g docker kaiIncorrect. -g changes the primary group.
Incorrect. -g changes the primary group.
useradd -aG docker kaiIncorrect. useradd is for creating new users.
Incorrect. useradd is for creating new users.
Try it yourself
An example you can run in a temporary verification environment.
usermod --help | grep -E -- '-a,|-G,'Expected result
appendとsupplementary groupsの説明行Key points
- -G sets the list
- -a appends
- Use -a with -G
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.