Chapter 4. User, Group and Permission

Groupadd (Add Group)

Groupadd (Add Group)
Tag:

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.

Command Line - INPUT
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.

Command Line - INPUT
cat /etc/group

You can find group_a at the bottom of the list.

Command Line - RESPONSE
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:

IdeaTips: 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.

Command Line - INPUT
grep group_a /etc/group
Command Line - INTERACTIVE
group_a:x:1002:

2. getent
Run the getent group command followed by the group name

Command Line - INPUT
getent group group_a
Command Line - RESPONSE
group_a:x:1003:

To prepare for the next section, add group_b and group_c.

Command Line - INPUT
sudo groupadd group_b
sudo groupadd group_c
grep group /etc/group
Command Line - RESPONSE
nogroup:x:65534:
group_a:x:1003:
group_b:x:1004:
group_c:x:1005:

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.

Command Line - INPUT
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.

Command Line - INPUT
cat /etc/group

You can find group_a at the bottom of the list.

Command Line - RESPONSE
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:

IdeaTips: 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.

Command Line - INPUT
grep group_a /etc/group
Command Line - INTERACTIVE
group_a:x:1002:

2. getent
Run the getent group command followed by the group name

Command Line - INPUT
getent group group_a
Command Line - RESPONSE
group_a:x:1003:

To prepare for the next section, add group_b and group_c.

Command Line - INPUT
sudo groupadd group_b
sudo groupadd group_c
grep group /etc/group
Command Line - RESPONSE
nogroup:x:65534:
group_a:x:1003:
group_b:x:1004:
group_c:x:1005:
Tag: