Useradd command examples usermod command examples
Groupadd command is used to create a new group account using the specified values with options or default values from the system. All information related to the group added into the system files as needed. There are many options present in group add command to change account settings of group.
We will understand all major options of groupadd command with examples:
How to create new group ?
Suppose, we want to create a new group and but we are not sure given group ID is used somewhere or not. So, in this case we can use –f option with –g option to create group forcefully. i.e. if gid is already used then it will take new gid and create the group.
As below example, 1010 gid is used already but due to –f option, command executes and it has taken next group ID i.e. 1011.
root@rhel:~# cat /etc/group | grep test
root@rhel:~# groupadd -fg 1010 login
root@rhel:~# cat /etc/group
How to create system group?
We can create system group with –r option with groupadd command. The numeric id of system groups always chosen in the SYS_GID_MIN-SYS_GID_MAX range, which is defined in login.defs instead of GID_MIN-GID_MAX
root@rhel:~# groupadd -r hello
root@rhel:~# cat /etc/group | grep hello
Recommended Article : Steps to extend the Logical Volume group
Groupdel command is used to delete a group. Before deleting the group, we need to must take care of following things:
- We can’t remove the primary group of any existing user.
- We need to remove user first and then group
- For safe side, we need to check all file systems to ensure that no files owned by this group.
Groupdel Command example:
[root@rhel ~]# groupdel test