Adding, modifying, and removing individual user accounts and groups of users is a routine but important activity that a system administrator frequently performs.
After introducing user account and group administration, this chapter describes the following tasks:
Note
You can also use the SysMan dxaccounts command to perform these tasks.
Administering user accounts and groups involves managing the contents of the system's password and group files. On standalone systems, the files you manage are /etc/passwd, which is documented in passwd(1), and /etc/group, which is documented in group(4).
On networked systems, typically, the Network Information Service (NIS) is for central account and group management. NIS allows participating systems to share a common set of password and group files. See the Network Administration manual for more information.
If enhanced security is enabled on your system, you need to administer more than the /etc/passwd file for security. For example, the protected password database is used for security related information such as minimum password lengths and password expiration times. These tasks are documented in the Security manual.
The passwd file for a standalone system identifies each user (including root) on your system. Each passwd file entry is a single line that contains seven fields. The fields are separated by colons and the last field ends with a new-line character. The syntax of each entry and the meaning of each field is as follows:
username:password:user_id:group_id:user_info:login_directory:login_shell
Create the login directory after adding a user account to the passwd file. Typically the user's name is used as the name of the login directory. Refer to the chown(1), mkdir(1), chmod(1), and chgrp(1) reference pages for additional information on creating a login directory.
All users are members of at least one group. The group file identifies the group name for a user. There are two primary reasons to group user accounts:
The group file is used for the following purposes:
Each entry in the group file is a single line that contains four fields. The fields are separated by colons, and the last field ends with a new-line character. The syntax of each entry and the meaning of each field is as follows:
groupname:password:group_id:user1 [ ,user2,...,userN ]
There is a limitation on the number of groups that a user can be in, as documented in group(4). The maximum line length is LINE_MAX as defined in the limits.h file. Digital recommends that user accounts be divided into a number of manageable groups.
There are several tools you use to administer user accounts and groups:
Note
The Account Manager is the preferred graphical interface for managing user accounts and groups. It replaces the Xsysadmin and XIsso commands.
This section describes how to:
The adduser utility automates the process of adding a user account. This utility performs the following tasks:
When you invoke the adduser utility, it responds with a series of messages and prompts you for the following information:
To use the adduser utility:
#
adduser
The utility responds with a series of prompts and messages.
The brackets ([ ]) indicate a default response.
Press Return to accept the default or enter a different response and press
Return, as shown in the following example:
Enter a login name for the new user (for example, john):
chris
Enter a UID for (chris) [5006]:
[Return]
Enter a full name for (chris):
Christopher Ryan
Enter a login group for (chris) [users]:
[Return]
Enter another group that (chris) should be a member of.
(<Return> only if none):
[Return]
Enter a parent directory for (chris) [/usr/users]:
[Return]
The shells are:
/usr/bin/sh /usr/bin/ksh /bin/csh /bin/ksh
/usr/bin/csh /bin/sh
Enter a login shell for (chris) [/bin/sh]:
[Return]
Adding new user ... Rebuilding the password database... 10 password entries, maximum length 145 Creating home directory...
You must enter a new password for (chris). Changing password for chris.
New password: Retype new password:
If you mistype the password during verification, no password is set and the account is disabled. To enable the user account, enter the passwd command followed by the user name.
The hashed password database does not exist. Do you want to create it ([y]/n)?
To create a hashed passwd database, enter yes at the prompt. The adduser utility creates one for you. If you do not want a hashed passwd database, enter no at the prompt. Refer to vipw(8) for information about editing the /etc/passwd file.
Note
A hashed passwd database allows for faster lookups of password file data and thus can improve system performance. Digital recommends you use a hashed passwd database.
To add a user account manually:
The following sections describe these tasks in detail.
Note
You cannot use the vipw utility to edit the protected password database on systems running with enhanced security. For these systems, you should use the adduser utility, the useradd command, or the Account Manager graphical interface to edit the passwd file.
To edit the passwd file:
#
vipw
root:TZVtfX5VbS3KY:0:1:System PRIVILEGED Account,,,:/:/bin/sh daemon:*:1:daemon uucp:*:2:uucpmarcy:*:201:20:Marcy Swanson,dev,x1234:/usr/users/marcy:/bin/sh
.
.
.
The previous example shows that user marcy has a UID of 201 and a GID of 20. The login directory is /usr/users/marcy and the Bourne shell (/bin/sh) is defined as the login shell. Since the password field contains an asterisk (*), user marcy cannot log in to the system. Section 9.2.2.4 describes how to add a password to the passwd file.
If a hashed passwd database exists, vipw uses the mkpasswd command to re-create it. A hashed passwd database is an indexed database that allows for faster searches of the passwd file. The following example shows the message displayed after closing the passwd file where a hashed passwd database existed previously:
10 password entries, maximum length 88
If a hashed passwd database does not exist, a message is displayed informing you that passwd it does not exist and asks if you want a database created. If you want a hashed passwd database, enter yes at the prompt. If you do not want a hashed passwd database, enter no at the prompt. Refer to vipw(8) for more information.
Note
In an NIS environment you can add a user account to either the local passwd file or the NIS distributed passwd file. Accounts added to the local passwd file are visible only to the system to which they are added. Accounts added to the NIS distributed passwd file are visible to all NIS clients that have access to the distributed file. Refer to nis_manual_setup(7) for more information on adding users in a distributed environment.
To add a new group or a user to an existing group, add a line entry to the group file, as follows:
#
cp group group.sav
system:*:0:root,diaz,kalle,marcy daemon:*:1:daemon uucp:*:2:uucp
.
.
.
users:*:15:diaz,kalle,marcy,chris
If at a later date you change the group a user belongs to, be sure to change the parent directory's GID also.
Users can customize their working environment by modifying their startup files. When a user logs in to the system, the login shell looks for startup files in the login directory. If the shell finds a startup file, it reads the file and executes the commands.
Table 9-1 displays each shell and the corresponding startup files.
Shell | System Startup File | Login Startup Files |
/bin/csh | /etc/csh.login | .cshrc, .login |
/bin/ksh | /etc/profile | .profile |
/bin/sh | /etc/profile | .profile |
The operating system uses these startup files to initialize local and global environment variables, shell variables, and terminal types. Use the following procedure to copy the startup files to the login directory of each user account:
#
cd /usr/skel
#
cp -R `ls -A` /usr/users/marcy
#
cd /usr/users/marcy
#
chmod 755 .??*
#
chown marcy .??*
#
ls -Al
Refer to the csh(1), ksh(1), and the sh(1) reference pages for more information on the shell commands.
Use the passwd command to assign a password for a user account. When you enter the passwd command, the program prompts you for a password. Each password must have at least five characters, but not more than eight, and can include digits, symbols, and the characters of your alphabet. The password cannot be all lowercase characters. The passwd command encrypts the specified password and inserts it in the password field of the passwd file.
To assign an initial password, use the following syntax:
passwd username
For example, to assign an initial password for user
marcy,
enter the following command:
#
passwd marcy
The system responds with the following prompts. Enter and verify the new
password for the user. To ensure confidentiality, the password will not be
displayed.
Changing password for marcy.
New password: Please don't use an all-lower case password. Unusual capitalization, control characters or digits are suggested. New password: Retype new password:
If a hashed passwd database is not in use, the system displays the following informational message:
Hashed database not in use, only /etc/passwd text file updated.
A hashed passwd database is an indexed database that allows for a faster search of the passwd file.
Once you have completed all the tasks for adding a user account, use the grpck and the pwck commands to check the accuracy of the group and passwd files.
Note
If your system is running enhanced security, you should also use the authchk utility to verify the accuracy of the protected password database.
The
grpck
command verifies that the number of fields, group name, GID, and all login
names that appear in the
passwd
file are correct. If any fields are incorrect,
grpck
writes the inconsistencies to standard output. For example:
#
grpck
users:*:15:diaz,kalle,marcy,chris,farkle farkle - Logname not found in password file [1] mem:*:3: Null login name [2]+: Too many/few fields [3]
Refer to the grpck(8) reference page for more information.
The
pwck
command checks for any inconsistencies in the
passwd
file. The
pwck
command verifies the number of fields, login name, UID, GID, existence
of a login directory, and optional program name. If any of the fields
are missing,
pwck
writes the inconsistencies to standard output. For example:
#
pwck
nobody:*Nologin:4294967294:4294967294:anonymous NFS user:/: Invalid UID [1] Invalid GID [2] Optional shell file not found [3]
Refer to the pwck(8) reference page for more information.
This section describes how to change information about a user account. The following tasks are discussed:
You should periodically change the root password. This protects the system from access by system users who should not have root access, as well as from external intruders.
There may be times when a user forgets his or her password. If this happens, change the user's password as described in Section 9.2.2.4 and tell the user the new password.
The user_info field in the passwd file contains the name, room number, office phone, and home phone of the user. To change this information, use the chfn command with the following syntax:
chfn [ username ]
For example, to change the information for user
marcy,
enter:
%
chfn marcy
The system displays information similar to the following example.
The brackets ([ ]) indicate a default response. Press Return to accept the
defaults or enter a different response and press Return.
Default values are printed inside of '[]'. To accept the default, type <return>. To have a blank entry, type the word 'none'.Name [Marcy Swanson]: [Return]
There may be a time when you want to change a user's login shell. To
see a list of the shells the user is allowed to select from, enter the
following command:
#
cat /etc/shells
The system prints a list similar to the following:
/bin/sh /bin/csh /bin/ksh
To change a user's login shell, use the chsh command with the following syntax:
chsh [ username ]
For example, to change user
marcy's
login shell from the Bourne shell to the C shell, enter:
#
chsh marcy
The system responds with the following information. At the prompt,
enter the new shell user
marcy
will be using. For example:
Old shell: /bin/shNew shell: /bin/csh
The next time user marcy logs in, she will be using the /bin/csh shell.
If you configured your system with file system quotas (also called disk quotas), you can set a quota for the number of inodes or disk blocks allowed for each user account or group on your system. To optimize disk space and to save yourself some work, set quotas by grouping user accounts according to their need for disk space. The following information is specific to the UNIX File System (UFS). If you are using the POLYCENTER Advanced File System (AdvFS), refer to Chapter 7.
You set quotas for user accounts and groups by file system. For example, a user account can be a member of several groups on a file system and also a member of other groups on other file systems. The file system quota for a user account is for a user account's files on that file system. A user account's quota is exceeded when the number of blocks (or inodes) used on that file system are exceeded.
Like user account quotas, a group's quota is exceeded when the number of blocks (or inodes) used on a particular file system is exceeded. However, the group blocks or inodes used only count toward a group's quota when the files that are produced are assigned the GID for the group. Files that are written by the members of the group that are not assigned the GID of the group do not count toward the group quota.
Note
Quota commands display block sizes of 1024-byte blocks.
To set a disk quota for a user, you can create a quota prototype or you can use an existing quota prototype and replicate it for the user. A quota prototype is an equivalence of an existing user's quotas to a prototype file, which is then used to generate identical user quotas for other users. Use the edquota command to create prototypes. If you do not have a quota prototype, create one by following these steps:
edquota proto-user users
For example, to set up a quota prototype named
large
for user
eddie,
enter the following command:
#
edquota large eddie
The program creates the large quota prototype for user eddie. You must use a real login name for the users argument.
To use an existing quota prototype for a user:
edquota -p proto-user users
For example, to set a disk quota for
marcy,
using the
large
prototype, enter:
#
edquota -p large marcy
Refer to quota(1) and edquota(8) for more information.
To remove a user's account, you must remove all the files and directories from the account and rename the user's entry for the group and passwd files. You can rename an account manually or by using the removeuser utility.
The removeuser utility automates the process of removing a user account. This utility performs the following tasks:
To use the removeuser utility, log in as root. At the prompt, enter:
#
removeuser
The program responds with a series of prompts and messages, as shown in the following example:
Enter a login name to be removed or <RETURN> to exit:
kalle
This is the entry for (kalle) in the /etc/passwd file:Is this the entry you want to delete (y/n)? y
kalle:/v7ZY9/tF1z5w:12:15:Kalle Anderson:/usr/users/kalle:/ksh
Working ... Entry for (kalle) removed. Searching relevant directories and files for user (kalle) ... None found.Do you want to remove the home directory, all subdirectories,
The files for (kalle) will be lost if not backed up.Are you sure you want to remove these files (y/n)? y
Removing /usr/users/kalle
Removing /usr/spool/mail/kalle
Finished removing user account for (kalle)
To manually remove a user account from your system:
The following sections describe each task and provide instructions for removing the files and directories.
Before removing files or directories from the user's account, follow these steps:
To remove a user's files and directories:
#
rm -r /usr/users/marcy
#
rm /usr/spool/mail/marcy
#
find /usr/users -user marcy -print
The find command locates user files that are links (identified by a notation of >1), user files within directories (identified by a notation of 1), or user directories (identified by a notation of 2). Refer to find(1) for more information.
#
rm /var/spool/cron/crontabs/marcy
#
rm /var/spool/cron/atjobs/marcy
Since users can be members of more than one group, modify all line entries in the group file that contain the user name within the user field.
To modify a group file entry:
#
cp group group.sav
system:*:0:root,diaz daemon:*:1:daemon uucp:*:2:uucp
.
.
.
users:*:15:diaz,chris
.
.
.
After you remove a user's account from the passwd file, the system can no longer identify the user. When removing an account for a user, use the vipw command to delete the line entry that identifies the user. The vipw command allows you to edit the passwd file and at the same time locks the file to prevent others from using it. Refer to Section 9.2.2.1 for information on editing the passwd file.
If you maintain accounting on a monthly basis, do not remove the line entry for the user's account from the passwd file until the monthly accounting has been done. Since the accounting commands access the passwd file, removing the user account line entry will create inaccuracies in your accounting.
However, since your primary goal is to restrict the user from gaining access
to the system, you can immediately suspend the user from logging in by
substituting NO_LOGIN for the encrypted user password in the
passwd
file. For example, the line entry for user
marcy
is as follows:
marcy:IK7Nv8f86Jo:201:20:Marcy Swanson,dev,x1234:/usr/users/marcy:/bin/csh
Replace the encrypted password with NO_LOGIN as shown in the following example:
marcy:NO_LOGIN:201:20:Marcy Swanson,dev,x1234:/usr/users/marcy:/bin/csh
To disable network logins, delete the user's account from any proxy files such as the user's .rhosts file.
This section describes how to:
The addgroup utility automates the process of adding a group to the /etc/group file.
When you invoke the addgroup utility, the program responds with a series of prompts and messages asking you for the following information:
To use the addgroup utility, log in as root and enter the following command at the prompt:
#
addgroup
The program responds with a series of prompts and messages. The brackets ([]) indicate the default response. Press Return to accept the default or enter a different response and press Return, as shown in the following example:
Enter a new group name or <Return> to exit:
newgroup
Enter a new group number [112]:
[Return]
Group newgroup was added to the /etc/group file.
.endtag
The addgroup utility adds the new group to the /etc/group file.
To add a new group, add a line entry to the group file:
#
cp group group.sav
system:*:0:root,diaz,kalle,marcy daemon:*:1:daemon uucp:*:2:uucp
.
.
.
users:*:15:diaz,kalle,marcy,chris
If at a later date you change the group a user belongs to, be sure to change the parent directory's GID also.
To remove a group that no longer has any members, delete the corresponding line from the group file as follows:
You can either assign a different group number or delete the current group number. If you assign a different group number, make sure that it corresponds to a current (or new) group entry in the group file. Refer to Section 9.2.2.1 for information on editing the passwd file.
#
cp group group.sav