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 0 Comments

[FreeBSD] How to allow Root access on FreeBSD over ssh protocol

This post was last updated on November 3rd, 2020 at 05:37 pmBy default FreeBSD does not allow root access over ssh protocol. So if you need to log on to

How To 0 Comments

How To Change The Execution Priority Of A Process In Linux?

This post was last updated on August 1st, 2020 at 12:24 pmIn Linux, a process is an instance of a program that is running on a computer. When a program

FreeBSD 0 Comments

How To Change The Hostname On A FreeBSD Machine?

The hostname is the name given to a computer so that it could be identified uniquely when connected to a network. The installer asks and setup the hostname while installing


No Comments Yet!

You can be first to comment this post!

Leave a Reply