FreeBSD add a user to group

by Vivek Gite on November 27, 2006 · 9 comments

Q. How do I add a user to group under FreeBSD operating system?

A. You need to use pw command. The pw utility is a command-line based editor for the system user and group files, allowing the superuser an easy to use and standardized way of adding, modifying and removing users and groups. First login as the root using su or sudo command.

Task: Add existing user to group

You would like to add existing user tom to secondary group called ftpusers. Type the command as follows:
# pw usermod tom -G ftpusers

You can add tom to secondary group ftpuser and wwwusers:
# pw usermod tom -G ftpusers,wwwusers

-G option Set the default groups in which new users are granted membership. This is a separate set of groups from the primary group, and you should avoid nominating the same group as both primary and extra groups.

Task: Add a new user to group

Add new user jerry to system and to secondary group sales:
# pw useradd jerry -G sales
# passwd jerry

First command adds user jerry to secondary group called sales. Second commands set a password for jerry.

Further readings:

=>Read pw command man page.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 9 comments… read them below or add one }

1 Tim May 29, 2009

On the FreeBSD systems I work with, I have to use the “-n” (name) switch before the username, or the command doesn’t work.

Reply

2 thommy December 13, 2009

It used for me BUT it kicked my main user out of
the group wheel. Seems like you have to append all groups, the user is in, or else he is not in the groups anymore, he used to be!

As for me, I now have no chance to remote administrate my server as root-remot-login is deactivated and this was the only-wheel-user :-(

Reply

3 thommy December 13, 2009

used = worked! plz change in above post and delete this one ;-) thx

Reply

4 Will January 17, 2010

Thommy, I’ve encountered the same problem. What did you mean by ‘used = worked!’?

Reply

5 rblon March 1, 2010

this advise SUCKS…
I did the same as Tim and thommy and I am unable to get root access, because I am kicked out of the wheel group.
Meanwhile ssh access for my root account is disabled, which means I just had to put in a support request with my data center.
Of course, I should have know better before simply using the command.
I advise anyone who wants to add a ‘user’ to a ‘group’ to use:
pw groupmod ‘group’ -m ‘user’
But I am afraid you will only read this comments after you screwed up…

Reply

6 rblon March 1, 2010

i meant “same as thommy and Will”

Reply

7 skvortsov September 9, 2010

Are you guys sure it kicked you from the wheel group? I tried this command and /etc/group no longer showed my user in wheel, but I was still able to su, and the command “id myname” showed that I was in fact a member of both groups. This is on FreeBSD 8.1.

Reply

8 sailorboy January 1, 2011

They filed to mention that the user gets pulled out of all their groups that isn’t listed in the list.
So if user jerry is in the groups mail, pop, imap, and office
and you execute
# pw usermod jerry -G ftpusers
Jerry is now in ONLY group ftpusers
Need to issue the command
# pw usermod jerry -G ftpusers, mail, pop, imap, office

Reply

9 fadm May 2, 2011

The correct command for this is “pw groupmod operator -m test”.
This way user test will be added to group operator without replacing or overwriting anything.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 14 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: