gpasswd command in Linux with examples

gpasswd command is used to administer the /etc/group and /etc/gshadow. As every group in Linux has administrators, members, and a password. It is an inherent security problem as more than one person is permitted to know the password. However, groups can perform co-operation between different users. This command assigns a user to a group with some security criteria. This command is called by a group administrator with a group name only which prompts for the new password of the group. System administrators can use the -A option to define group administrator(s) and -M option to define members. They have all rights of the group administrators and members.

Syntax:

gpasswd [option] group

Options: Here only -A and -M options can be combined.

  • -a, –add : This option is used to add a user to the named group.
  • -d, –delete : It is used to remove a user from the named group.
  • -r, –remove-password : It is used to remove the password from the named group.
  • -R, –restrict : This option will restrict the access to the named group.
  • -A, –administrators : Set the list of administrative users.
  • -M, –members : It set the list of group members.
  • -h, –help : It displays the help message and exit.
    $ sudo gpasswd -h 

Example: Creating a group and adding a user to it. After that deleting the user.

  • Adding a group named as geeks.
    $ sudo groupadd geeks

  • To display the created group with their id you can use:
    $cat /etc/group
  • Now the group geeks is added so now execute command under to add the user to group geeks:
    $ sudo gpasswd -a umang geeks

  • Deleting the created user from group geeks.
    $ sudo gpasswd -d umang geeks


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.