Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX System Administrator's Guide: Configuration Management: HP-UX 11i Version 3 > Chapter 4 Configuring Users and Groups

Managing Users and Groups with Commands

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

Automating the Process of Adding a User

When you have several users to add to a system, you can save time by:

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

OptionMeaning

-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 groupPrimary working group name or group ID. Group must exist. The default is users (group ID 20).
-G groupsComma-separated list of secondary groups. Groups must exist.
-k skeldirSkeleton 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 shellShell. The default is /sbin/sh.
-u uidUser 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.

Manually Adding a User

Use the following steps to add a user from the command line.

  1. Add the user to the/etc/passwd file.

    As root, use the/usr/sbin/vipw command to edit /etc/passwd. See vipw(1M), passwd(4), and passwd(1).

    For example, you might want to add this line for user tom:

    tom:*:102:20:Tom,,,:/home/tom:/usr/bin/sh

    This creates the entry and disables logins (the * in the password field). The home directory is /home/tom and the login shell is /usr/bin/sh. The user ID is 102 and the primary group ID is 20, conventionally, users.

  2. Use the passwd command to set an initial password for the account. For example:

    # passwd tom Changing password for tom New password: password Re-enter new password: password Passwd successfully changed
  3. Use the passwd command to force a password change at the next login. For example:

    # passwd -f tom
  4. Create a home directory. For example:

    # /usr/bin/mkdir /home/tom

    Change the ownership of the directory to the user’s name. For example:

    # /usr/bin/chown tom:users /home/tom
  5. Ensure that the user has the appropriate shell start-up files to execute when logging in.

    You can create standard start-up files (templates) that can be copied to users’ directories. The directory most often used for this purpose is/etc/skel. See “Skeleton Directory”.

    For example:

    # cp /etc/skel/.profile /users/tom/.profile
  6. Change the ownership of the start-up file to the new user’s account and group. For example:

    # /usr/bin/chown tom:users .profile
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 2008 Hewlett-Packard Development Company, L.P.