I already discussed how to add a user to a group in FreeBSD. This article is about removing a user from a group. Before we get into the discussion to remove a user from a group I will briefly explain about users and groups in FreeBSD.
A group is a list of users. It makes it easier to define the permissions such as read, write, and execute for a system resource that is to be shared among the users of that group. You can set permission to ensure that files are accessible to users of a particular group like accounts, hr, marketing, etc.
Kernel identifies a user by its UID and group by its GID. The group name to GID mapping is given in /etc/group file. A superuser can modify it by using a text editor. Alternatively, pw
can be used to add and modify a group in FreeBSD.
How to see the list of users having in a group
To display the list of users or the members of a group you will have to use the following command in your terminal –
pw groupshow group_name
For example –
pw groupshow management
As you can see in the image above currently there are two members in the management group.
How to remove a user from a group
To add or remove a group in FreeBSD we will use pw
utility. The pw
can be used to add, remove, modify, and display the users and groups. It has various command-line options that you can use in shell scripts.
Use the following command to remove a user from a group –
pw groupmod group_name -d user_name
For example –
pw groupmod management -d lalit
Now after executing the above command if you run –
pw groupshow management
you will see that user lalit is now removed from the management group.
Removing multiple users from a group in a single command
In a single command, you can remove the multiple users from a group in FreeBSD. Use the following command to remove the users from a group –
pw groupmod group_name -d user1,user2,user3
For example –
To remove both the user from the management group I will use the following command –
pw groupmod management -d lalit,vaibhav
This will remove the both the members from the management group.
Now If you want to know more about the uses of pw
then see its manual page by running following command in your terminal –
man pw
Ok, that’s all for now, If you have anything to say on this topic then you can write to us in the comments below.