How to Add or Remove Linux User From Group

Introduction

Adding or removing users from groups in Linux is an important task for system administrators. It allows them to control user access to system resources and manage user privileges. This tutorial will explain how to add or remove a user from a group in Linux using the command line. It will also discuss the different types of groups and how to view the groups a user belongs to. Finally, it will provide some useful tips for managing user groups.

How to Add or Remove Linux User From Group

1. To add a user to a group, use the usermod command.

Syntax:

usermod -a -G groupname username

Example:

usermod -a -G sudo username

2. To remove a user from a group, use the gpasswd command.

Syntax:

gpasswd -d username groupname

Example:

gpasswd -d username sudo
[ad_1]

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 Appreciate What We Do Here On Jassweb, You Should Consider:

Jassweb is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit Jassweb! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

[ad_2]

How to Add or Remove Linux User From Group

Adding or removing a user from a group in Linux is a common task for system administrators. It is important to understand how to manage user groups in order to ensure that users have the correct access to resources. In this article, we will discuss how to add or remove a user from a group in Linux.

Adding a User to a Group

The first step in adding a user to a group is to use the usermod command. This command is used to modify a user’s account information, including the user’s group membership. To add a user to a group, use the following syntax:

usermod -a -G groupname username

The -a option is used to append the user to the specified group. The -G option is used to specify the group name. Replace groupname with the name of the group you want to add the user to, and replace username with the name of the user you want to add.

Removing a User From a Group

To remove a user from a group, use the same usermod command with the -G option. However, this time you will use the -G option without the -a option. The syntax for this command is as follows:

usermod -G groupname username

Replace groupname with the name of the group you want to remove the user from, and replace username with the name of the user you want to remove.

Conclusion

In this article, we discussed how to add or remove a user from a group in Linux. We used the usermod command to add or remove a user from a group. We also discussed the syntax for the command and how to use it to add or remove a user from a group.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00