How to add and remove users from groups in Linux

Do you want your Linux user to give an access to the root group or adding him some more privilages like making him a user with apache group, here How to add and remove users from groups in Linux for any user by command #usermod -G Groupname Username. This can be used by most of user where you need to allow your user to execute the files which belongs to apache group in case of web servers.

First you check the current existing groups assigned to user by using “groups” command

$ groups
techobia

Add user to a group

# usermod -G "GroupName" "username"
e.g. 
# usermod -G root techobia
## Here I assigned this user to root Group

Now again check it groups

# su techobia
$ groups
techobia root

Remove User from all other groups

# usermod -G "" username
e.g.
# usermod -G "" techobia
# su techobia
$ groups
techobia

removes all secondary/supplementary groups from username, leaving them as a member of only their primary group.

Permanently asign user to work as different primary group
#usermod -g root techobia

Now after logout and login agian This user will make any new files or documenst as root as his primary group. This is most required when we are using apache dir where we need the user has all privilages but all new fils to be a member of apache group so executed by apache without any issue.