After introducing user account and group administration, this chapter describes the following tasks:
You can also use the SysMan dxaccounts command to perform these tasks. Note
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.
username :password: user_id: group_id: user_info: login_directory: login_shell
groupname: password: group_id: user1 [user2,...,userN]
To edit the passwd file:
Table 10-1 displays each shell and the
corresponding startup files.
10.1 Understanding User Accounts and Groups
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).
10.1.1 The Password File
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:
finger
(1) and chfn
(1)
reference pages for more information.chown
(1), mkdir
(1), chmod
(1), and chgrp
(1)
reference pages for additional information on creating a login directory.sh
(1) reference
page for information on the Bourne shell. Users can change their login shell
by using the chsh command. Refer to Section 10.3.3
and the chsh
(1) reference page for more information.
10.1.2 The Group File
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:
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.
10.1.3 The Administrative Tools
There are several tools you use to administer user accounts and groups:
dxaccounts
(1X) reference page.
Note
useradd
(8), usermod
(8), userdel
(8), groupadd
(8), groupmod
(8), and groupdel
(8).adduser
(8) and addgroup
(8). These utilities
provide simple, interactive scripts you can use to add new user accounts and
groups. These utilities can be used only on systems that do not use NIS.vipw
(8),
allows you to invoke an editor in order to edit the password file manually.
You can use the utility to edit the local password database, but you cannot
use it to edit the NIS database. Additionally, you cannot use the vipw utility on systems that have enhanced security. The vipw command allows you to edit the passwd file
and at the same time locks the file to prevent others from modifying it.
This command also does consistency checks on the password entry for root and
does not allow a corrupted root password to be entered into the passwd file.
10.2 Adding a User Account
This section describes how to:
10.2.1 Adding a User Account with the adduser Utility
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]
prpasswd
(4) and authcap
(4) for more information
about the fields in the protected password database.
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
10.2.2 Adding a User Account Manually
To add a user account manually:
The following sections describe these tasks in detail.
10.2.2.1 Adding a User Account to the passwd File
Note
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:
# vipw
root:TZVtfX5VbS3KY:0:1:System PRIVILEGED Account,,,:/:/bin/sh
daemon:*:1:daemon
uucp:*:2:uucp
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 10.2.2.4 describes how to
add a password to the passwd file.
.
.
.
marcy:*:201:20:Marcy Swanson,dev,x1234:/usr/users/marcy:/bin/sh
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
nis_manual_setup
(7) for more information on adding users
in a distributed environment.
10.2.2.2 Adding an Entry to the group File
To add a new group or a user to an existing group, add a line entry
to the group file, as follows:
If at a later date you change the group a user belongs to,
be sure to change the parent directory's GID also.
# cp group group.sav
system:*:0:root,diaz,kalle,marcy
daemon:*:1:daemon
uucp:*:2:uucp
.
.
.
users:*:15:diaz,kalle,marcy,chris
10.2.2.3 Providing the Default Shell Scripts
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.
Shell | System Startup File | Login Startup Files |
---|---|---|
/bin/csh | /etc/csh.login | .cshrc, .login |
/bin/ksh | /etc/profile | .profile |
/bin/sh | /etc/profile | .profile |
# cd /usr/skel # cp -R `ls -A` /usr/users/marcy
# cd /usr/users/marcy # chmod 755 .??* # chown marcy .??*
# ls -Al
csh
(1), ksh
(1), and the sh
(1) reference
pages for more information on the shell commands.
To assign an initial password, use the following syntax:
passwdusername
For example, to assign an initial password for user marcy, enter the following command:
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:
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:
There may be times when a user forgets his or her password. If this
happens, change the user's password as described in Section 10.2.2.4
and tell the user the new password.
chfn[username]
For example, to change the information for user marcy, enter:
chsh[username]
For example, to change user marcy's login
shell from the Bourne shell to the C shell, enter:
The next time user marcy logs in, she will be using
the /bin/csh shell.
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.
edquotaproto-user users
For example, to set up a quota prototype named large for user eddie, enter the following command:
edquota -pproto-user
users
For example, to set a disk quota for marcy,
using the large prototype, enter:
To use the removeuser utility, log in as root. At
the prompt, enter:
To remove a user's files and directories:
To modify a group file entry:
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:
When you invoke the addgroup utility, the program
responds with a series of prompts and messages asking you for the following
information:
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:
10.2.2.4 Assigning a Password
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.
# 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.
10.2.2.5 Verifying the Accuracy of the group and passwd Files
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
# 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.
# 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.
10.3 Changing Information in a User Account
This section describes how to change information about a user account.
The following tasks are discussed:
10.3.1 Changing Passwords
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.
10.3.2 Changing the user_info Field
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 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]
Room number (Exs: 597E or 197C) []: [Return]
Office Phone (Ex: 6426000) []: 3311
Home Phone (Ex: 9875432) []: [Return]
10.3.3 Changing the Login Shell
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 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/sh
New shell: /bin/csh
10.3.4 Setting File System Quotas
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 8.
10.3.4.1 Understanding User Account and Group Quota Limits
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.Note
10.3.4.2 Setting File System Quotas for User Accounts
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:
To use an existing quota prototype for a user:
# edquota large eddie
The program creates the large quota
prototype for user eddie. You must use a real login name
for the users argument.
Refer to
# edquota -p large marcy
quota
(1) and edquota
(8) for more information.
10.4 Removing a User Account
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.
10.4.1 Removing a User Account with the removeuser Utility
The removeuser utility automates the process of removing a user account.
This utility performs the following tasks:
# 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:
kalle:/v7ZY9/tF1z5w:12:15:Kalle Anderson:/usr/users/kalle:/ksh
Is this the entry you want to delete (y/n)? y
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,
files and mail for (kalle) (y/n)? y
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)
10.4.2 Removing a User Account Manually
To manually remove a user account from your system:
The following sections describe each task and provide instructions
for removing the files and directories.
10.4.3 Removing a User's Files and Directories
Before removing files or directories from the user's account, follow
these steps:
# 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
10.4.4 Removing a User's Account from the group File
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.
# cp group group.sav
system:*:0:root,diaz
daemon:*:1:daemon
uucp:*:2:uucp
.
.
.
users:*:15:diaz,chris
.
.
.
10.4.5 Removing a User's Account from the passwd File
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 10.2.2.1 for information on editing the passwd file.
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.
10.5 Adding and Removing Groups
This section describes how to:
10.5.1 Adding a Group with the addgroup Utility
The addgroup utility automates the process of adding
a group to the /etc/group file.
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.
10.5.2 Adding a Group Manually
If at a later date you change the group a user belongs to,
be sure to change the parent directory's GID also.
# cp group group.sav
system:*:0:root,diaz,kalle,marcy
daemon:*:1:daemon
uucp:*:2:uucp
.
.
.
users:*:15:diaz,kalle,marcy,chris
10.5.3 Removing a Group
To remove a group that no longer has
any members, delete the corresponding line from the group
file as follows:
# cp group group.sav