How To Add A User To A Group In FreeBSD?

How To Add A User To A Group In FreeBSD?

 

This post was last updated on August 1st, 2020 at 12:12 pm

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 list the groups in a terminal

The list of the groups with their group id is given in the /etc/group file. To display the list of groups in your terminal use the following command –

less /etc/group

How to add a group in FreeBSD

To add 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.

Now to add a group use the following command –

pw groupadd group_name

For example –

pw groupadd management

A group with the name management will be added to the system.

You can check the newly added group by using –

pw groupshow management

How to add a user to a group

By using pw we can add a user to a group. Now if you use pw groupshow command you will find that there are no members are added in the newly created group. Use the following command to add a user to a group –

pw groupmod group_name -M user_name

For example –

pw groupmod management -M lalit

The option -M will add a user to an empty group or it will replace the existing user of a group.

Use the following command to see the members of a group –

pw groupshow management

As you can see in the image above user lalit is now a member of the management group.

How to add multiple users in a group

To add multiple users to a group you will have to use the option -m with the given command. Now to add another user named vaibhav to the management group run the following command in your terminal-

pw groupmod management -m vaibhav

If you run the following command you will see that the multiple users are added to the group-

pw groupshow management

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, I discussed removing a user from a group in FreeBSD in another article. If you have anything to say on this topic then you can write to us in the comments below.

Previous [ubuntu] Bluetooth audio - disconnecting
Next How To Remove A User From A Group In FreeBSD?
 

About author

You might also like

FreeBSD Topics 0 Comments

How To Execute A Command With Superuser Privilege In FreeBSD?

This post was last updated on August 1st, 2020 at 10:28 amA superuser or root user is a most privileged user account in FreeBSD. It has access to all the

How To 0 Comments

Saving a CD-ROM to file and Mounting it on Red Hat Linux 6.0 and Newer

This post was last updated on June 1st, 2020 at 06:48 pmYou can actually pull in a copy of a cdrom, then mount it into your file system. You would

How To 0 Comments

How To Find IP Address From Domain Name In Linux/Unix?

This post was last updated on August 1st, 2020 at 03:35 pmBefore we start running a command to find the IP addresses from the domain name. First, we will discuss

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply