Using the useradd, usermod, and userdel Commands |
|
You can use the useradd command
to add users, usermod to modify them, and userdel to delete them. See the useradd(1M), usermod(1M), and userdel(1M) manpages.
useradd has the form:
/usr/sbin/useradd [option]... username
username is the login
name for the new user.
Some of the options are described in Table 4-3. For all the options and
complete information on the command, see useradd(1M).
Table 4-3 useradd Options
Option | Meaning |
---|
-b b_dir | Default base directory
for user home directory. The default is /home. |
-c "comments" | Full name or other comments.
This is often a comma-separated string in the form: fullname,location,workphone,homephone |
-d dir | Home directory path name.
The default is b_dir/username. |
-e date | Account expiration date.
The default is none. To use the -e option, you must
enable shadow passwords. For details on how to do that, see pwconv(1M). |
-f n | Number of days the account
can be inactive before being disabled. As with the -e option, to use the -f option you must enable shadow
passwords. For details on how to do that, see pwconv(1M). |
-g group | Primary working group name or
group ID. Group must exist. The default is users (group ID 20). |
-G groups | Comma-separated list of secondary
groups. Groups must exist. |
-k skeldir | Skeleton directory containing
initialization files. The default is /etc/skel. |
-m | Create the home directory in addition to defining
user. The default is don’t create home directory. |
-s shell | Shell. The default is /sbin/sh. |
-u uid | User ID. The default is the first
available number after 100. |
The following command creates a new user account,
adds patrick to the primary working group (called users), creates a home directory, and sets up a default
Korn shell:
# useradd -g users -m -k /etc/skel -s /usr/bin/ksh patrick |
The resulting entry in the /etc/passwd file is:
patrick:*:104:20::/home/patrick:/usr/bin/ksh
|
You can make a script with as many instances of
the useraddcommand as necessary. You can set different
defaults with the useradd -D command.
After the accounts are created, set their initial
passwords with the passwd command.