Linux is by default a multi-user system, thus user management is one of the fundamental tasks of a system administrator. User management includes everything from creating, updating, and deleting user accounts or user groups on a Linux system.
Check a User Group in Linux
Check a user group, by running the following groups command:
# groups rootadminz
rootadminz : rootadminz superior
To check your own groups, just run the groups command without any argument.
# group
root
Add a User to a Group in Linux
Before adding a user to a group, ensure that the user exists on the system. To add a user to a certain group, use the usermod command with the -a flag, and the -G option specifies the actual groups in the following format.
In this example, rootadminz is the username and postgres is the group name:
# usermod -aG postgres rootadminz
# groups rootadminz
Remove a User from a Group in Linux
To remove a user from a group, use the gpasswd command with the -d option as follows.
# gpasswd -d rootadminz postgres
# groups rootadminz
Additionally, on Ubuntu and it’s derivative, you can remove a user from a specific group using the deluser command as follows (where rootadminz is the username and postgres is the group name).
$ sudo deluser rootadminz postgres