In this article, we will explain how to add user to group and how to remove a user from a group in Linux systems. We will also briefly explain what is a Linux user and a group.
Linux is a multiuser operating system. In a multiuser environment, it is a common administration task to create new users, modify existing users, or remove users. For ease of access management, users are assigned to groups. Creating, deleting, and modifying groups is also another common administration task.
A Linux user is a person (like a human being) who can log in to the system or can be a system user (may or may not have the login shell).
A Linux group is typically defined as a role, where the role will have certain permissions/privileges. This role can be added to any number of users that needs these permissions/privileges.
So as you know by now, in Linux, you can create a user account and assign the user to different groups.
How to Add User to Group in Linux
For adding a user to a group, we will be using usermod command.
To add an existing user to a group, use the usermod -a -G command followed the name of the group and the user:
sudo usermod -a -G <group name> <user name>
For example, let’s say you want to add the user ubuntu to the group linux then you would use the following command
sudo usermod -a -G linux ubuntu
How to Remove a User from Group in Linux
For removing a user from a group, we will be using gpasswd command.
To remove a user from a group, use the gpasswd -d command followed the name of the user and the group name:
sudo gpasswd -d <user name> <group name>
For example, let’s say you want to remove the user ubuntu from the group linux then you would use the following command