Managing Users/Groups With pw
Updated: 01/07/2004
General Information
This guide will let you know how to manage FreeBSD accounts using pw, a critical application which can manipulate a lot of things that have to do with the /etc/passwd file and /etc/groups file. It can also set certain things like how long the account can be active, until what date it is active and other cool things. The easiest way to learn how to use pw is to play with it on a test install.Requirements
Installation
There is no installation needed for this. As long as you have a FreeBSD system with version 5.x or 4.x (I don't doubt it is the same app, which minimally changes from version to version).pw user help
Usage of pw is really easy, the man page however makes it look like it is the hardest tool ever to use, in fact it comes with its in built in help menu.| # | pw |
|
usage: pw [user|group|lock|unlock] [add|del|mod|show|next] [help|switches/values] |
| # | pw user add help |
|
usage: pw useradd [name] [switches] -V etcdir alternate /etc location -C config configuration file -q quiet operation Adding users: -n name login name -u uid user id -c comment user name/comment -d directory home directory -e date account expiry date -p date password expiry date -g grp initial group -G grp1,grp2 additional groups -m [ -k dir ] create and set up home -s shell name of login shell -o duplicate uid ok -L class user class -h fd read password on fd -Y update NIS maps -N no update Setting defaults: -V etcdir alternate /etc location -D set user defaults -b dir default home root dir -e period default expiry period -p period default password change period -g group default group -G grp1,grp2 additional groups -L class default user class -k dir default home skeleton -u min,max set min,max uids -i min,max set min,max gids -w method set default password method -s shell default shell -y path set NIS passwd file path |
| # | pw user add myname -d /usr/home/special/myname -s /usr/local/bin/bash -m |
| # | pw user del myname |
| # | pw user del help |
|
usage: pw userdel [uid|name] [switches] -V etcdir alternate /etc location -n name login name -u uid user id -Y update NIS maps -r remove home & contents |
| # | pw user del myname -r |
pw user mod helps us with that. It has quite a few options as well.| # | pw user mod help |
|
usage: pw usermod [uid|name] [switches] -V etcdir alternate /etc location -C config configuration file -q quiet operation -F force add if no user -n name login name -u uid user id -c comment user name/comment -d directory home directory -e date account expiry date -p date password expiry date -g grp initial group -G grp1,grp2 additional groups -l name new login name -L class user class -m [ -k dir ] create and set up home -s shell name of login shell -w method set new password using method -h fd read password on fd -Y update NIS maps -N no update |
| # | pw user mod myname -G wheel |
pw group help
Now that we know how to manipulate users, or at least quite a bit, but we also want to be able to manipulate groups. Manipulating groups, is the same as a user, except that instead ofpw user help, we type pw group help.| # | pw group add help |
|
usage: pw groupadd [group|gid] [switches] -V etcdir alternate /etc location -C config configuration file -q quiet operation -n group group name -g gid group id -M usr1,usr2 add users as group members -o duplicate gid ok -Y update NIS maps -N no update |
| # | pw group add mygroup -M myname |
| # | pw group del help |
|
usage: pw groupdel [group|gid] [switches] -V etcdir alternate /etc location -n name group name -g gid group id -Y update NIS maps |
| # | pw group del mygroup |
pw to see all the options.| # | pw group mod help |
This guide is © 2004 - 2010 Bert JW Regeer.
Author: Bert JW Regeer
bsdguides at 0x58 dot com