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.
usermod -G docker kaiIncorrect. -G alone replaces the existing list with docker.
usermod -g docker kaiIncorrect. -g changes the primary group.
useradd -aG docker kaiIncorrect. 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
Account record
Identity attributes such as a user ID, home directory, and login shell.
Group membership
Primary and supplementary groups used during permission checks.
Password aging
State and time limits that control password changes and account access.