Let’s talk about group management. To create a new group use the groupadd command. 1
In its simplest form you just specify the group name as argument. I’m creating a new group called 2
“engineering”. 3
Of course, I'm running the command as root. 4
And the group was added to the group file. 5
Let's see the last three groups. 6
This is the newly created group. 7
If you want to list all groups, just display the entire contents of the group file cat/etc/group 8
these are all the groups. 9
Once the group is created, you can start adding users to the group;use the usermod command with 10
the capital -G option. 11
I'm creating a new user using the default options and then adding it to the group. 12
So sudo useradd u1 13
And I can also add the user to the group when I'm creating it. 14
usermod -aG engineering the group name and the user name u2; u2 already exists 15
so u3 16
And groups u3 17
It belongs to u3 as its primary group and to engineering as a secondary group. To add the user to the 18
new group, as a secondary group, use the -G option. 19
So sudo usermod -G engineering and the username u1. Don't forget to use the minus -a 20
to append the user to the group, so the user will remain part of all the other groups to which it already 21
belongs to. 22
So -a 23
Of course, it's engineering with double e and groups u1 24
I've added the user to the group, now the user is part of the engineering group. To change the name 25
of the group, used the group groupmod command like this: 26
sudo groupmod -n engineers the new group name and the old group name, 27
the group name 28
I'm renaming: engineering. 29
In fact, I have renamed the group.To delete a group run the groupdel command followed 30
by the groupname. Let's delete the group called engineers. 31
sudo groupdel engineers 32
On success, the groupdel command does not print any output. if the group plan to remove doesn't 33
exist, the system will print an error message saying that the group does not exist. 34
I'm running the command again and it says group engineers does not exist. 35
It was already deleted. 36
Note that it's not possible to move the primary group of an existing user without first removing the 37
user.