Group Management
In Linux operating systems, group management is as important as user management. Groups are used to collectively assign the same access rights and permissions to multiple users. This enables system administrators to easily control resources and access. This section focuses on how to create, manage, and delete groups in Linux.
What is a Group in Linux?
In Linux systems, a group is a collection of users who have specific permissions and access rights. Groups are used to simplify access control in file systems and make user management more efficient.
Creating a Group
To create a new group, use the groupadd command. For example, to create a group named development, use the following command:
root@hackerbox:~$ sudo groupadd developmentYou can view the groups we have created in the /etc/group file.
root@hackerbox:~$ cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
...
development:x:1004:The /etc/groupfile may contain many groups, making it difficult to find the group you are looking for. To simplify your task, you can use the command below with grep to display only a specific group:
root@hackerbox:~$ cat /etc/group | grep development
development:x:1004:Adding Users to a Group
To add users to the created group, use the usermod command with the -aG option. The -aG option adds the user to the specified group while preserving existing group memberships. For example, to add the user "john" to the "development" group, use the command below:
root@hackerbox:~$ sudo usermod -aG development johnDeleting a Group
To remove a group that is no longer needed, use the groupdel command. For example, to delete the "development" group, use the following command:
root@hackerbox:~$ sudo groupdel developmentThis command deletes the "development" group from the system.
Last updated