In previous article, we covered how to Add a user to group in Ubuntu. When a user becomes a part of the group, he/she can have access to files, directories or peripherals as described in group permissions. But, at times, for numerous reasons we may want to remove the user from group. In this article, we would cover how to remove a user from group in Ubuntu.
It is worth mentioning here that, the primary group of the user shouldn’t be removed. If that happens then the user may face login issues. So, we don’t recommend removing a users’ primary group. There are multiple methods available to remove a user from group in Ubuntu. But, we decided to cover that through deluser command-line utility.
The benefit of using deluser command-line utility is – even if we accidentally try to remove a users’ primary group, it would throw the following error –
/usr/sbin/deluser: You may not remove the user from their primary group.
Note: Following operations require superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.
Remove a user from group in Ubuntu
As already discussed, we utilize deluser command-line utility. So, use the following syntax to remove a user from group in Ubuntu –
sudo deluser <username> <groupname>
This should return with the following –
Removing user '<username>' from group '<groupname>' ... Done.
For instance, if we want to remove a user – testuser from the group – xyz then,
sudo deluser testuser xyz
It would return with the following –
Removing user 'testuser' from group 'xyz' ... Done.
If you want to know whether the user is still a part of the group then, use id command-line utility –
id <username>
Continuing with the above example, for user – testuser, it should be –
id testuser
It would show all the groups a user is currently part of.
In conclusion, never remove a users’ primary group and we have used deluser command-line utility to remove a user from group here.