User groups are used to configure file system access of the operating system. Since in Linux all objects of the OS are files, then with the help of groups you can configure or restrict access to any features of the system.
In a previous article, we talked about how to see a list of Linux groups that the user is member of. Here we will discuss how to remove a user from the group, so it can no longer have access to the files with that group permissions.
We will use gpasswd command. It has the following syntax:
gpasswd -d user_name group_name
The -d option means remove.
For example lets remove testuser from the adm group:
$ sudo gpasswd -d testuser adm Removing user testuser from group adm
With the usermod command you can remove the current user from all additional groups:
sudo usermod -G "" user_name
Just be careful with this command by applying it to the current user, otherwise you will remove yourself from the sudo group and will no longer be able to perform administrative actions. In Ubuntu, where there is no direct access to the root user, this can create serious problems for newbies.
In some distributions, you can also use the deluser command. In the same way, first specify the user name, and then the group name from which we are going to remove it:
sudo deluser testuser adm
If you accidentally delete a user from the group in which he should be, you can return everything back. See the article “How to add a user to a Linux group“.