# Add yourself to the 'wheel' and 'operators' group



## afroman10496 (Dec 27, 2009)

Sorry, total n00b here 
I just installed FreeBSD using this guide and I accidentally forgot to add myself to those groups in the user configuration  How can I just add myself? Thanks in advance!


----------



## caesius (Dec 27, 2009)

edit /etc/group as root and add yourself


```
operator:*:5:root,<you>
wheel:*:0:root,<you>
```


----------



## afroman10496 (Dec 27, 2009)

thanks!


----------



## Antti (Dec 27, 2009)

Or better use pw:
`# pw group mod group_name -m user_name`


----------



## meine (Feb 12, 2018)

Antti said:


> Or better use pw:
> `# pw group mod group_name -m user_name`



I tried to use `pw` to add my username to the wheel and operator groups -- wheel to use `$ su -` and operator to mount USB thumb drives.

When I (as root) add my user name to one of both groups, the other 'group membership' vanishes. It appears as if a regular user can only be part of one ' admin' group. `id <user name>` only shows the own user group and the last other group added.

Is this a normal behaviour of `pw`? And/or is direct editing /etc/group a better way?

TIA,


----------



## ralphbsz (Feb 12, 2018)

It should work.  The command "pw groupmod admin -m foo" is supposed to add the user named "foo" to the group admin.  It should neither remove foo from other groups, nor remove other users from group admin.  Note that the syntax given in the example above is different, and doesn't agree with the man page for command `pw`.

As to your question "is `pw` better/worse than editing /etc/group"?  That's a loaded question.  Editing the file directly allows an experienced user to have faster and more direct control of which user is in what group, and is more efficient.  It also allows an inexperienced user to make mistakes faster and more efficiently, creating more damage.  And it allows making big mistakes (like getting the syntax of the lines wrong) which can't even be done with the `pw` command.  If you feel comfortable with the file format, and are good at editing files, and know how to be careful, I would edit the file directly.  Otherwise, I would suggest that you use the `pw` command for a while, and look at the resulting /etc/group file and see how it changes, to verify that you did everything right.  Even if you don't have the courage to edit that file directly, you need to know how to read it.  The manpage group(5) is your friend.


----------



## scottro (Feb 13, 2018)

That should definitely work. `pw groupmod wheel -m john`. Then a second one for the second group.  I thought that a comma separated list would work, such as wheel,operator, but it doesn't seem to do so.

EDIT: Doing this on CURRENT, so I'm not sure if that's the reason, or if the syntax has changed (and maybe that's why the handboook now uses groupmod instead of usermod) but it used to work, unless my memory's totally gone with

`pw usermod john -G wheel,operator`

However, doing that on a laptop running CURRENT is removing user john from their present groups.


----------



## SirDice (Feb 13, 2018)

`pw usermod myuser -g wheel`
Sets the _primary_ group of myuser to wheel. A user account can only have one _primary_ group.
`pw usermod myuser -G wheel`
Sets _additional_ groups. Note the difference between -g and -G. Also note that -G removes any existing group membership.

The easiest, less error-prone, is to use `pw groupmod wheel -m myuser`. This _adds_ the myuser account to the group wheel.



```
-g group      Set the account's primary group to the given group.  group
                   may be defined by either its name or group number.

     -G grouplist  Set secondary group memberships for an account.  grouplist
                   is a comma, space, or tab-separated list of group names or
                   group numbers.  The user is added to the groups specified
                   in grouplist, and removed from all groups not specified.
                   The current login session is not affected by group
                   membership changes, which only take effect when the user
                   reconnects.  Note: do not add a user to their primary group
                   with grouplist.
```


```
-m newmembers  Similar to -M, this option allows the addition of existing
                    users to a group without replacing the existing list of
                    members.  Login names or user ids may be used, and
                    duplicate users are silently eliminated.
```
See pw(8)


----------



## meine (Feb 14, 2018)

In my attempt I messed up between `pw [B]usermod[/B]` and `pw [B]groupmod[/B]` -- makes quite a difference.

TNX for keeping me sharp and the incentive to better RTFM


----------



## sidetone (Feb 14, 2018)

In /etc/group, I'm guessing the primary user to a group is the first user listed?


----------



## SirDice (Feb 15, 2018)

sidetone said:


> In /etc/group, I'm guessing the primary user to a group is the first user listed?


Primary groups are not in groups, the group itself is there but not the user.

```
dice@molly:~ % getent group dice
dice:*:1001
```
As you can see, it looks like a group with no members. But:

```
dice@molly:~ % id dice
uid=1001(dice) gid=1001(dice) groups=1001(dice)
```
The primary group membership is only in passwd:

```
dice@molly:~ % getent passwd dice
dice:*:1001:1001:SirDice:/home/dice:/bin/tcsh
```


----------

