How to create new groups?
How to add a user to a group?
How to remove a user from a single group?
- Primary Group – When a user is created, automatically a group is created with its username, it’s called primary group. A user creates files or directory and operating system assigns the group to them.
- Secondary Group – A user can belong to more than one group. It is used to share file or directory with the
Create A New Group
For example, you want to create a group name centos. You can check created group from path cat /etc/group
[root@localhost ~]# groupadd centos
[root@localhost ~]# cat /etc/group
How to add user in a Group
Let us assume, want to add user “
[arun@localhost ~]$ groups arun
[root@localhost ~]# usermod -aG centos arun
usermod: used to modify user group.
- -a: –append, Add the user to the supplementary group(s). Use only with the -G option.
- centos: it is the group name
arun: user name
How to remove a user from a single group
Remove user arun only from centos group
root@localhost ~]# gpasswd -d arun centos
- /etc/groups: Keeps the record of the groups created on a system.