December 12, 2018

How to Add a User to a Group on FreeBSD

FreeBSD Logo

By adding users to separate groups you can easily handle different access rights. For this you need to use the pw command. With this command-line based editor the superuser root can edit system users and groups in a standardized way on FreeBSD. This includes adding, modifying and removing users and groups.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Add a new user to a group

Add a new user joe to the system and add this user to the sales group.

pw useradd joe -G sales

Set a password for the new user joe.

passwd joe

Add an existing user to a group

Add the existing user sam to the sales group.

pw usermod sam -G sales

You can add a user to more than one group with one command.
The following command will add the user sam to the group sales and ftpusers.

pw usermod sam -G sales,ftpusers

Speak Your Mind