The gpasswd command is used in linux to remove user from group, add users to group, list group members and set password for a group. Gpasswd command alters '/etc/group' and '/etc/gshadow' files in Linux.
In this tutorial we learn how to manage Linux groups using gpasswd command.
Gpasswd Command Syntax
Lets check the syntax for gpasswd command and its options.
gpasswd [options] group
-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.
Add a User to a group using gpasswd comand
Let check how to add a 'user1' to a group 'sales'
$ gpasswd -a user1 sales
Add multiple user to a group
To add multiple users to sales group following below command:
$ gpasswd -M user1,user2,user3 sales
Remove a user from group
We can use
-d option to remove a user from a group.
Following command will remove user 'user2' from the 'sales' group.
$ gpasswd -d user2 sales
Set a user as group administrator
We use -A option to set a user as group administrator.
The following example set 'user1' and 'user2' as the group admin for 'sales' group.
$ gpasswd -A user1,user2 sales
$ gpasswd -A user1 linuxgroup
Set password for a group
Its very rare we use group password but I like to show you that there is an option for it.
$ gpasswd linuxgroup
Changing the password for group linuxgroup
Re-enter new password:
In this tutorial we learned how to use gpasswd command to manage Linux groups. I hope you enjoyed reading this tutorial and please leave your suggestions in the below comment section.