Modify groups
To modify an existing group in Linux, the groupmod command is used. Using this command you can change the GID of a group, set the group password and change the name of a group.
Here is a list of groupmod’s options:
Here is a simple example of this command’s usage. To change the name of the group from test_gr to test_group, we can use the following command:
Add users to groups
Interestingly enough, you can’t use the groupmod command to add a user to a group. Instead, the usermod command with the -G option is used. When adding a user to a new group, be sure to also list all of the user’s current groups. Omitting any of the user’s current groups will remove the user from those groups!
To add bob to the group test_group, we can use the following command:
We can list the groups a user is in by using the groups command:
If you don’t wont to list all the user’s current groups when adding a user to a new group, you can use the -a option. For example, if we want to add jwilliams to the group cdrom and keep the current group membership, we can use the following command: