≡ Menu

pw command

FreeBSD: Delete User Account Command

How do I remove the tom user under FreeBSD operating system using command line options?
[click to continue…]

Delete SSH Keys

One my user leaves the office and I'd like to disable her access to our UNIX / Linux system. How do I delete ssh key from the UNIX systems so that user can not log in?
[click to continue…]

FreeBSD Change User Password Shell Script

How do I change user password using a shell script under FreeBSD operating systems?
[click to continue…]

FreeBSD pw command examples

Q. How do I use FreeBSD pw command to add users?

A. The pw command 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.

Add user called tom

To add a user called tom, enter:
# pw useradd -n tom -s /bin/csh -m
# passwd tom

Where,

  • -n tom : Username
  • -s /bin/csh : Set shell
  • -m : Create and setup home directory /home/tom

Delete a user called tom

Enter the command:
# pw userdel -n tom -r
Note that -r option remove home directory & its contents.

Getting help with pw command

For a summary of options available with each command, you can use
pw [command] help

For example, lists all available options for the useradd operation.
# pw useradd help
# man pw

FreeBSD add a user to group

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.

FreeBSD locking an account

The pw utility is a command-line utility for the FreeBSD system user and group files, allowing the superuser an easy to use and standardized way of adding, modifying and removing users and groups. Same utility provides ability to locking or unlocking FreeBSD user accounts.

FreeBSD locking an account command

Syntax:
pw lock {username}

Example

Lock user account named vivek. Login as a root user and type following command:

# pw lock vivek

FreeBSD unlocking an account command

Syntax:
pw unlock {username}

Example

Unlock user account named vivek. Login as the root user and type the following command:

# pw unlock vivek

See also: