YouTip LogoYouTip

Linux Comm Gpasswd

# Linux gpasswd Command [![Image 3: Linux Command Manual](#) Linux Command Manual](#) Linux gpasswd is a management tool for the group files /etc/group and /etc/gshadow under Linux. It is used to add a user to a group or remove a user from a group. ### Syntax gpasswd group_name **Options**: * -a: Add a user to a group; * -d: Remove a user from a group; * -A: Specify administrators; * -M: Specify group members, similar in purpose to -A; * -r: Remove the password; * -R: Restrict users from logging into the group; only members of the group can use newgrp to join it. ### Example If the system has a user account named `peter`, and this account is not a member of the `groupname` group, using `newgrp` requires entering the password. gpasswd groupname This allows the user to temporarily join and become a member of that group. Afterward, files created by `peter` will belong to the `groupname` group. This method allows `peter` to temporarily use a different group when creating files, instead of his own primary group. Therefore, setting a password with `gpasswd groupname` allows anyone who knows the group password to temporarily switch to having the privileges of the `groupname` group. gpasswd -A peter users This makes `peter` the administrator of the `users` group, allowing him to perform the following operations: gpasswd -a mary users gpasswd -a allen users **Note**: To add a user to a specific group, you can use the command `usermod -G group_name user_name`. This command adds a user to a specified group but will clear any previously assigned groups. Therefore, to add a user to a group while preserving previously assigned groups, please use the `gpasswd` command to add the user: gpasswd -a user_name group_name [![Image 4: Linux Command Manual](#) Linux Command Manual](#)
← File NextPython Five Fish β†’