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
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
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
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
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.
We are thankful for your never ending support.
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.