How to use the gpasswd command In Linux
There is another command, the gpasswd command, to remove users from a group. The syntax of the command is simple:
gpasswd [options...] <groupname>
Now, to delete a user from a group, we use the -d option followed by the username.
gpasswd -d <username> <groupname>
Step 1: Deleting a user from a group using the user command.
We shall use the same user ‘dummy’ as in the previous method. But, this time we shall delete the user from the ‘video’ group. The command we need is modified as follows:
gpasswd -d dummy video
We can recheck the existing groups using the same method as in Method 1:
As we can see, the user was a member of the video group and then, we deleted it using gpasswd.
Step 2: Verifying the result (Optional)
We can again verify using the groups command as before:
groups dummy
As we can verify here, the dummy user is no longer a member of the video group.
How to Remove Users from Groups in Linux?
Groups in Linux are an important part of organizing the system’s access control. Creating separate groups for separate types of roles of users allows the administrator to manage the access control of the Linux system efficiently.
It is an essential skill to understand how to add, remove, and update users in a group from Linux. In this article, we shall learn various methods for removing a user from a group in Linux using different command line tools. We shall use Kali Linux for demonstration in this article.