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:

linux groupmod 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:

linux changing the group name

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:

linux adding users to a group

We can list the groups a user is in by using the groups command:

linux 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:

usermod keep primary group

Geek University 2022