UNIX System Administration Handbook - Evi Nemeth [63]
For example, to create a new user “hilbert” with useradd (using the system defaults), you could simply run:
# useradd hilbert
This command would create the following entry in /etc/passwd. Note that useradd puts a star in the password field, effectively disabling the account until you assign a real password.
hilbert:*:105:20::/home/hilbert:/bin/sh
useradd is generally more useful when given additional arguments. In the next example, we specify that hilbert’s primary group should be “faculty” and that he should also be added to the “famous” group. We also override the default home directory location and ask useradd to create the home directory if it does not already exist:
# useradd -c "David Hilbert" -d /home/math/hilbert -g faculty -G famous -m
-s /bin/tcsh hilbert
This command creates the following passwd entry:
hilbert:*:105:30:David Hilbert:/home/math/hilbert:bin/tcsh
It also adds hilbert to the “faculty” and “famous” groups in /etc/group, creates the directory /home/math/hilbert, and populates it based on the contents of /etc/skel. On Solaris (and Linux, if shadow passwords are in use), an entry for hilbert would also be created in /etc/shadow.
You can determine the default useradd settings with useradd -D; with HP-UX and Red Hat Linux, you can set those defaults in the /etc/default/useradd file.
usermod modifies an account that already exists and takes many of the same flags as useradd. For example, we could use the following command to set an expiration date of July 4, 2002 on hilbert’s account:7
# usermod -e "July 4, 2002" hilbert
The userdel command deletes user accounts, effectively undoing all the changes made by useradd. To remove hilbert, we would use the following command:
# userdel hilbert
This command removes references to hilbert in the passwd, shadow (if it is in use), and group files. By default, it would not remove hilbert’s home directory. (At our site, we generally keep deleted users’ home directories around for a few weeks anyway to avoid having to restore requested data from a backup tape.)
FreeBSD comes with a pw command that acts like useradd and friends. pw is useful for executing scripted operations on the password file and may be of general use if you’re accustomed to the useradd-style commands available on other systems. However, unlike useradd, FreeBSD’s pw command chooses its behavior based on its first argument. For example, to add the user hilbert with pw, we would run
# pw useradd hilbert
FreeBSD also comes with adduser and rmuser Perl scripts that you can either use as supplied or modify to fit your local needs. We find the adduser and rmuser scripts to be more useful than pw for interactively adding and removing users. FreeBSD’s rmuser script does a good job of removing the deleted users’ files and processes (a task that other vendors’ userdel programs do not even attempt).
Unlike pw, useradd, and userdel, adduser and rmuser are interactive programs that prompt you for information about each account to be created or removed. You can set site-wide defaults in /etc/adduser.conf. By default, adduser copies startup files from the directory /usr/share/skel.
1. FreeBSD allows login names to be up to 16 characters long, and Red Hat allows 32 characters.
2. Most, but not all, systems use DES to encrypt passwords. You can only copy encrypted passwords among machines that use the same encryption algorithm.
3. Uniquid is available from ftp://ftp.colorado.edu/its/unix/src/uniquid.tar.gz.
4. When Honeywell took over the computer division of GE, GECOS was changed to GCOS; both spellings survive today.
5. There is still a hard limit on the total number of processes and open files that the kernel can support, but no artificial limit is imposed.
6. The kernel doesn’t actually care what’s in /etc/passwd or /etc/group; it only cares about raw UID and GID numbers. passwd and group store account information for use by high-level software such