This procedure works for all Linux distributions running any desktop environment and shell. The procedures outlined below were tested using Ubuntu 19.10 with the Budgie desktop environment and Zsh, running in a Hyper-V virtual machine on Windows 10.
The gpasswd command serves as a shell-based front end to administer the /etc/group and /etc/gshadow files. In addition to short-cutting the processes for assigning users and groups (which typically occurs with the usermod command), gpasswd sets an optional password on a group.
How to Add a User to a Group
- Use the command sudo addgroup [groupname] to create a group, if you haven’t already created one.
- The command to modify an existing group’s password, gpasswd, takes the following general form: gpasswd [option] group
The options available for this command include:
-a, –add: Add a user to the named group.
-d, –delete: Remove a user from the named group.
-h: Display a help summary, then exit.
-Q, –root: Apply changes in the group’s root directory and use the config files from it.
-r, –remove-password: Remove the group password. Only people who are already added to the group can activate it for the session using the newgrp command.
-R, –restrict: Restrict access to the group and set a default group password of !. People must supply the password to join the group using newgrp.
-A, –administrators: Sets the list of people who have the authority to administer users (add/delete) or change the group password.
-M, –members: Sets the list of group members.