Create a new group using the GROUPADD command in Linux

Home > Search > Linux commands
  by

The groupadd command without any options can be used to create a new group. For example, to create a group named group1.

[root@server1 ~]# groupadd group1

 

The records in the /etc/group file will contain 4 fields. The 4 fields are: group name:password:GID:group members.

The /etc/group file contains group1. The group will not be secured with a password, in this example the GID is 1001, and the group does not have any members.

[root@server1 ~]# cat /etc/group
group1:x:1001:

 


Password

The -p or --password option can be used to secure a group with a password. Adding or changing a group password using the groupadd or groupmod commands will create an unencrypted, cleartext password. Adding or changing a group password using the gpasswd command will create an encrypted password.

[root@server1 ~]# groupadd -p Password123 group1

 

Regardless if the group is or is not secured with a password, the second field of /etc/group will display an "x", so viewing the /etc/group file does not help to know if the group is secured with a password.

[root@server1 ~]# cat /etc/group
group1:x:1001:

 

The /etc/gshadow file will contain the group password.

[root@server1 ~]# cat /etc/gshadow
group1:Password123::

 


GID

The -g or --gid option lets you choose the GID when creating a group.

[root@server1 ~]# groupadd -g 1234 group1

 

In this example, the GID of group1 is 1234.

[root@server1 ~]# cat /etc/group
group1:x:1234:

 

By default, the system expects each group to have a unique GID. When attempting to add a new group using a GID already in use, an error will appear.

[root@server1 ~]# groupadd -g 1234 group2
groupadd: GID '1234' already exists

 

The -o or --non-unique option can be used to create a new group using a GID already being used by another group.

[root@server1 ~]# groupadd -og 1234 group2

 

In this example, there will now be two groups with GID 1234.

[root@server1 ~]# cat /etc/group
group1:x:1234:
group2:x:1234:

 


System group

The -r or --system option can be used to create a system group.

[root@server1 ~]# groupadd -r sysgroup

 

In this example, thereis a system group named sysgroup.

[root@server1 ~]# cat /etc/group
sysgroup:x:999:

 


Add group members

There is no option to add members to a group with the groupadd command. The usermod command can be used to add members to a group.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments