Manage Linux Group Using gpasswd Command

The gpasswd command (As defined in the man page) is used to administer /etc/group, and /etc/gshadow. Every group can have administrators, members and a password.

Command Options

-a, --add user Add the user to the named group.
-d, --delete user Remove the user from the named group.
-A, --administrators user,... Set the list of administrative users.
-M, --members user,... Set the list of group members.

gpasswd examples

Let us assume that we have a group named sales and three users user1,user2,user3.

Add User

To add user1 to sales group

gpasswd -a user1 sales

Add multiple user

To add multiple users to sales group

gpasswd -M user1,user2,user3 sales

Remove user

To remove user2 from sales group

gpasswd -d user2 sales

How to set a user as group administrator

gpasswd -A user group

or

gpasswd -A user1,user2 sales

Example :

gpasswd -A nixsavy linuxgroup

Set password for group

$ gpasswd linuxgroup

Changing the password for group linuxgroup

New Password:

Re-enter new password:

Browse Linux commands

Bobbin Zachariah 9:00 am

Comments

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

1 Comment

  1. The example for -M above implies adding user1,user2,user3 in addition to users already there.
    The man pages for gpasswd clearly state that option -M is to "Set the list of group members."
    This will destroy any existing set of members, so therefore is not an implicit "add" unless the group was empty to begin with.