groupadd (Add Group)
The groupadd
command is used to create a new user group. The group data is recorded under the /etc/group file. To execute this command, you need to run it with superuser privileges.
Create a new group
To create a new group is simple, run the groupadd
command followed by a new group name. For example, to create group_a, run the command below.
sudo groupadd group_a
Confirm group
As group information is recorded under the /etc/group file, run the cat command to check if the new group is added.
cat /etc/group
You can find group_a at the bottom of the list.
root:x:0:
daemon:x:1:
:
:
systemd-coredump:x:999:
ubuntu:x:1000:
user_a:x:1001:
user_b:x:1002:
group_a:x:1003:
Tips: Command to check registered groups
There are other ways to confirm a list of groups.
1. grep
Run the grep
command followed by the group name and /etc/group
.
grep group_a /etc/group
group_a:x:1002:
2. getent
Run the getent group
command followed by the group name
getent group group_a
group_a:x:1003:
To prepare for the next section, add group_b and group_c.
sudo groupadd group_b
sudo groupadd group_c
grep group /etc/group
nogroup:x:65534:
group_a:x:1003:
group_b:x:1004:
group_c:x:1005: