How to Add or Remove Linux User From Group

Linux is by default a multi-user system (meaning many users can connect to it simultaneously and work), thus Linux user management is one of the fundamental tasks of a system administrator, which includes everything from creating, updating, and deleting user accounts or user groups on a Linux system.

In this short quick article, you will learn how to add or remove a user from a group in a Linux system.

Check a User Group in Linux

To check a user group, just run the following groups command and provide the username (tecmint in this example) as an argument.

# groups tecmint

tecmint : tecmint wheel

To check your own groups, just run the groups command without any argument.

# group

root
Check a User Group in Linux
Check a User Group in Linux

Add a User to a Group in Linux

Before trying to add 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 which tells the usermod to add a user to the supplementary group(s), and the -G option specifies the actual groups in the following format.

In this example, tecmint is the username and postgres is the group name:

# usermod -aG postgres tecmint
# groups tecmint
Add User to Group in Linux
Add User to Group in Linux

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 tecmint postgres
# groups tecmint
Remove User from Group in Linux
Remove User from Group in Linux

Additionally, on Ubuntu and it’s derivative, you can remove a user from a specific group using the deluser command as follows (where tecmint is the username and postgres is the group name).

$ sudo deluser tecmint postgres

For more information, see the man pages for each of the different commands we have used in this article.

You will also find the following user management guides very useful:

If you read this far, tweet to the author to show them you care. Tweet a thanks
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.