6.5. Modifying Accounts

pw is a powerful and flexible means to modify accounts, but adduser is recommended for creating new accounts, and rmuser for deleting accounts.

chpass allows both the system administrator and normal users to adjust passwords, shells, and personal information. passwd is the more common means to change passwords specifically, however.

6.5.1. adduser

adduser is a simple program for adding new users. It creates passwd and group entries for the user, as well as creating their home directory, copy in some default dotfiles from /usr/share/skel, and can optionally mail the user a welcome message.

To create the initial configuration file, use adduser -s -config_create. [1]Next, we configure adduser defaults, and create our first user account, since using root for normal usage is evil and nasty.

Example 6-1. Changing the configuration for adduser

    # adduser -v
    Use option ``-silent'' if you don't want to see all warnings and questions.
    Check /etc/shells
    Check /etc/master.passwd
    Check /etc/group
    Enter your default shell: csh date no sh tcsh [sh]: tcsh
    Your default shell is: tcsh -> /usr/local/bin/tcsh
    Enter your default HOME partition: [/home]:
    Copy dotfiles from: /usr/share/skel no [/usr/share/skel]: 
    Send message from file: /etc/adduser.message no 
    [/etc/adduser.message]: no
    Do not send message
    Use passwords (y/n) [y]: y
    
    Write your changes to /etc/adduser.conf? (y/n) [n]: y
    
    Ok, let's go.
    Don't worry about mistakes. I will give you the chance later to correct any input.
    Enter username [a-z0-9_-]: jru
    Enter full name []: J. Random User
    Enter shell csh date no sh tcsh [tcsh]: 
    Enter home directory (full path) [/home/jru]: 
    Uid [1001]: 
    Enter login class: default []: 
    Login group jru [jru]: 
    Login group is ``jru''. Invite jru into other groups: guest no 
    [no]: wheel
    Enter password []: 
    Enter password again []: 
    
    Name:     jru
    Password: ****
    Fullname: J. Random User
    Uid:      1007
    Gid:      1007 (jru)
    Class:    
    Groups:   jru wheel
    HOME:     /home/jru
    Shell:    /usr/local/bin/tcsh
    OK? (y/n) [y]: y
    Added user ``jru''
    Copy files from /usr/share/skel to /home/jru
    Add another user? (y/n) [y]: n
    Goodbye!
    #

In summary, we changed the default shell to tcsh (an additional shell found in packages), and turned off the sending of a welcome mail to added users. We then saved the configuration, and then created an account for jru, and we made sure jru is in wheel group (which we'll see is important later).

Note: The password you type in isn't echoed, nor are asterisks displayed. Make sure you don't mistype the password twice :-)

Note: Just use adduser without arguments from now on, and you won't have to go through changing the defaults. If the program asks you to change the defaults, exit the program, and try the -s option.

6.5.2. rmuser

rmuser removes users from the system, including any traces beyond the user database.

rmuser performs the following steps:

  1. Removes the user's crontab(1) entry (if any).

  2. Removes any at(1) jobs belonging to the user.

  3. Kills all processes owned by the user

  4. Removes the user from the system's local password file.

  5. Removes the user's home directory (if it is owned by the user)

  6. Removes the incoming mail files belonging to the user from /var/mail.

  7. Removes all files owned by the user from temporary file storage areas such as /tmp.

  8. Finally, removes the username from all groups to which it belongs in /etc/group.

    Note: If a group becomes empty and the group name is the same as the username, the group is removed; this complements the per-user unique groups created by adduser(8).



rmuser can't be used to remove superuser accounts, since that is almost always an indication of massive destruction.

By default, an interactive mode is used, which attempts to make sure you know what you're doing.

Example 6-2. rmuser interactive account removal

    # rmuser jru
    Matching password entry:
    jru:*:1000:1000::0:0:J. Random User:/home/jru:/usr/local/bin/tcsh
    Is this the entry you wish to remove? y
    Remove user's home directory (/home/jru)? y
    Updating password file, updating databases, done.
    Updating group file: trusted (removing group jru -- personal group is empty) done.
    Removing user's incoming mail file /var/mail/jru: done.
    Removing files belonging to jru from /tmp: done.
    Removing files belonging to jru from /var/tmp: done.
    Removing files belonging to jru from /var/tmp/vi.recover: done.
    #

6.5.3. pw

pw is a command line utility to create, remove, modify, and display users and groups, and functions as an editor of the system user and group files.

It is designed to be useful both as a directly executed command and for use from shell scripts.

pw(8) has all the information.

6.5.4. chpass

chpass changes user database information such as passwords, shells, and personal information.

Only system administrators, as the superuser, may change other users' information and passwords with chpass.

Passed no options, besides the optional username, chpass displays an editor containing user information, and upon exit from the editor, attempts to change the information in the user database.

Example 6-3. Interactive chpass by Superuser

    #Changing user database information for jru.
    Login: jru
    Password: *
    Uid [#]: 1000
    Gid [# or name]: 1000
    Change [month day year]:
    Expire [month day year]:
    Class:
    Home directory: /home/jru
    Shell: /usr/local/bin/tcsh
    Full Name: J. Random User
    Office Location:
    Office Phone:
    Home Phone:
    Other information:

The normal user can change only a small subsection of this information, and only for themselves.

Example 6-4. Interactive chpass by Normal User

    #Changing user database information for jru.
    Shell: /usr/local/bin/tcsh
    Full Name: J. Random User
    Office Location:
    Office Phone:
    Home Phone:
    Other information:

Note: chfn and chsh are just links to chpass, as are ypchpass, ypchfn, and ypchsh. NIS support is automatic, so specifying the yp before the command is not necessary.

6.5.5. passwd

passwd is the usual way to change your own password as a user, or another user's password as the superuser.

Note: Users must type in their original password before changing their password, to prevent an unauthorized person from changing their password when the user is away from their console.

Example 6-5. passwd

    % passwd
    Changing local password for jru.
    Old password:
    New password:
    Retype new password:
    passwd: updating the database...
    passwd: done
    
    # passwd jru
    Changing local password for jru.
    New password:
    Retype new password:
    passwd: updating the database...
    passwd: done

Note: yppasswd is just a link to passwd. NIS support is automatic, so specifying the yp before the command is not necessary.

Notes

[1]

The -s makes adduser default to quiet. We use -v later when we want to change defaults.

For questions about FreeBSD, e-mail <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.