FreeBSD add user command freebsd, user, add user command, freebsd add user
FreeBSD add user command
Below FreeBSD command will add user name named newuser with expiration date on 1st of September 2008 (-e), with default shell bash (-s). The user's home directory (/home/newuser) will be automatically created (-m argument).
For my normal users I have created a special login class called restricted which has limited number of processes, open files and so on. This user will automatically have this login class set (-L).
Additionally, after executing this command I will have a prompt in which newuser's password will be asked.
$ pw useradd -n newuser -e 01-09-2008 -m -s /usr/local/bin/bash -h 0 -L restricted -c "New user on FreeBSD"
pw useradd's arguments:
The following options apply to the useradd and usermod commands: -c comment This field sets the contents of the passwd GECOS field, which normally contains up to four comma-separated fields containing the user's full name, office or location, and work and home phone numbers. These sub-fields are used by convention only, however, and are optional. If this field is to contain spaces, you need to quote the comment itself with double quotes `"'. Avoid using commas in this field as these are used as sub-field separators, and the colon `:' character also cannot be used as this is the field sep- arator for the passwd file itself. -n name Specify the user/account name. -e date Set the account's expiration date. Format of the date is either a UNIX time in decimal, or a date in `dd-mmm-yy[yy]' format, where dd is the day, mmm is the month, either in numeric or alphabetic format ('Jan', 'Feb', etc) and year is either a two or four digit year. This option also accepts a relative date in the form `+n[mhdwoy]' where `n' is a decimal, octal (leading 0) or hexadecimal (leading 0x) digit followed by the number of Minutes, Hours, Days, Weeks, Months or Years from the current date at which the expiration date is to be set. -m This option instructs pw to attempt to create the user's home directory. While primarily useful when adding a new account with useradd, this may also be of use when moving an existing user's home directory elsewhere on the file system. The new home directory is populated with the con- tents of the skeleton directory, which typically contains a set of shell configuration files that the user may person- alize to taste. Files in this directory are usually named dot.<config> where the dot prefix will be stripped. When -m is used on an account with usermod, existing configura- tion files in the user's home directory are not overwritten from the skeleton files. -s shell Set or changes the user's login shell to shell. If the path to the shell program is omitted, pw searches the shellpath specified in /etc/pw.conf and fills it in as appropriate. Note that unless you have a specific reason to do so, you should avoid specifying the path - this will allow pw to validate that the program exists and is exe- cutable. Specifying a full path (or supplying a blank "" shell) avoids this check and allows for such entries as /nonexistent that should be set for accounts not intended for interactive login. -h fd This option provides a special interface by which interac- tive scripts can set an account password using pw. Because the command line and environment are fundamentally insecure mechanisms by which programs can accept information, pw will only allow setting of account and group passwords via a file descriptor (usually a pipe between an interactive script and the program). sh, bash, ksh and perl all pos- sess mechanisms by which this can be done. Alternatively, pw will prompt for the user's password if -h 0 is given, nominating stdin as the file descriptor on which to read the password. Note that this password will be read only once and is intended for use by a script rather than for interactive use. If you wish to have new password confir- mation along the lines of passwd(1), this must be imple- mented as part of an interactive script that calls pw. -L class This option sets the default login class for new users.
Now that the user was added to the system, we can show user's details.
Show user details on FreeBSD
$ pw usershow newuser newuser:*:4015:4016:restricted:0:1220223600:New user on FreeBSD:/home/newuser:/usr/local/bin/bash
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.