TrumanWong

gpasswd

Management tool for workgroup files under Linux

Supplementary instructions

gpasswd command is a management tool for workgroup files /etc/group and /etc/gshadow under Linux.

grammar

gpasswd(options)(parameters)

Options

-a: Add user to group;
-d: Delete the user from the group;
-A: Specify administrator;
-M: Specifying group members has the same purpose as -A;
-r: delete password;
-R: Restrict users from logging into the group. Only members of the group can use newgrp to join the group.

Parameters

Group: Specify the workgroup to manage.

Example

If the system has a peter account, but the account itself is not a member of the groupname group, you need to enter a password to use newgrp.

gpasswd groupname

Let the user temporarily join as a member of this group, and the file group created by peter will also be groupname. Therefore, this method can temporarily allow peter to use other groups when creating files, instead of the group where peter itself is located.

Therefore, using gpasswd groupname to set the password allows people who know the group password to temporarily switch to the groupname group function.

gpasswd -A peter users

In this way, Peter is the administrator of the users group and can perform the following operations:

gpasswd -a mary users
gpasswd -a allen users

Note: To add a user to a certain group, you can use the usermod -G group_name user_name command to add a user to a specified group, but the previously added group will be cleared.

So when you want to add a user to a group while retaining the previously added group, please use the gpasswd command to add the operating user:

gpasswd -a user_name group_name