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:

Deleting a user from the group using gpasswd command

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

Verifying the results

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.

Similar Reads

Pre-requisites

A Linux machine with root privileges. Basic understanding of Linux terminal and commands....

Method 1: Using the `deluser` command

The deluser is a Linux command for deleting users from systems/groups. The syntax of the command is :...

Method 2: Using the gpasswd command

There is another command, the gpasswd command, to remove users from a group. The syntax of the command is simple:...

Method 3: Editing the /etc/group file

In this method, we shall edit the /etc/group file, which contains information regarding the users, to remove a specific user from the group....

Conclusion

In this article, we learned three different methods for removing a user from a group in linux. First we used the deluser command and removed a user from a group. Then, we saw how to use the gpasswd command for the same purpose. Lastly, we used a more direct approach and edited the /etc/group file to remove users from a group....