Overview

Creating, deleting and updating FreeBSD users and groups is achieved with the id and pw commands.

The pw commands requires superuser permissions, which is granted by prepending sudo to the start of each command.

Note

For more information, read the pw and id man pages.

ActionCommand
Show userid {user}
Show users in a grouppw group show {group}
Create userpw user add {user}
Create grouppw group add {group}
Add user to grouppw group mod {group} -m {user}
Remove user from grouppw group mod {group} -d {user}
Delete userpw group del {user}
Delete grouppw user del {group}

Show user

To show a user's uid, gid and groups, use the id command.

For the current user execute id:

# id
uid=0(root) gid=0(wheel) groups=0(wheel)

To show information for a different user, execute id {user}, substituting the user of choice:

# id newuser
uid=1002(newuser) gid=1002(newuser) groups=1002(newuser)

Additional useful command parameters you can use when displaying a user:

  • -p: make the output human-readable

Create user

To create a user along with its home directory, execute pw user add {user} -m:

# pw user add newuser -m
# id newuser
uid=1002(newuser) gid=1002(newuser) groups=1002(newuser)

There are additional command parameters you can use when creating a user:

  • -n name: the user/account name
  • -d dir: home directory
  • -G grouplist: secondary group memberships
  • -m: create the user's home directory
  • -s shell: Sets the user's login shell

Create group

Create a new group using the command pw group add {group}:

# pw group add newgroup
# pw group show newgroup
mygroup:*:1001:

Add user to group

To add a user to an existing group, execute pw group mod {group} -m {user}:

# pw group mod mygroup -m newuser
# pw group show mygroup
mygroup:*:1001:newuser

Remove user from group

To remove a user from a group, execute pw group mod {group} -d {user}:

# pw group mod mygroup -d myuser
# pw group show mygroup
mygroup:*:1001:

Delete user

To delete an existing user, execute pw user del {user}:

# pw user del myuser

Delete group

To delete an existing group, execute pw group del {group}:

# pw group del mygroup