- Account Configuration Files
- Admintool
- User Administration Shell Commands
- Shells
- User Account Commands
- Chapter Summary
- Test Yourself
5.5 User Account Commands
Let's explore some common account-oriented commands and functions that users can perform.
Finding Files by Username or Group
This section describes a few ways to find files on a system belonging to a specific user or group.
The -l option of the ls command shows the username and group name associated with files and directories. When ls shows the numeric value for a username or group, this is an indication that the username or group has been removed from the system. The -n option of the ls command shows the numeric userid and groupid.
The find command can be used to locate files on a system belonging to a particular user or group. The syntax of the find command is find directory expression, where directory is the place where find should start searching, and expression is one or more of the following:
-user username. Search for files owned by username; username can be the actual username or the numeric userid.
-group groupname. Search for files owned by groupname; groupname can be the actual group name or the numeric groupid.
-name filename. Search for files named filename.
-print. Find will list all files found matching criteria.
-exec command {} \;. Execute command with the located file or files as arguments to command.
-type x. Find files of type x, where x is one of: f (ordinary file), d (directory), b (block special file), c (character special file), D (door), l (symbolic link), p (named pipe), or s (socket).
Some examples of the find command follow:
# find /export/home user mark print # find /tmp user 1002 exec ls la {} \; # find /export/tools group toolmgr name "*tmp" exec rm {} \;
In the first example, find will list all files owned by username mark in or below the directory /export/home. In the second example, find will locate all "orphaned" files with userid 1002 in the directory /tmp and perform an ls la on each located file. In the last example, all files whose names end in "tmp" with groupid toolmgr in or below the directory /export/tools are removed.
Exam Notes
Think About It . . .
What command syntax would be used to change the ownership of "orphaned" files to that of another user? The find and chown commands could be chained together. For example:
find / -user 1002 -print | xargs chown terry
What Users Are Logged In?
who Command
The who command is used to display which users are currently logged into the system. The format of the who command is who [options]. The options for who are:
- -a. Specify all (-bdlpru) options.
- -b. Show the system's boot time.
- -d. Show dead processes.
- -H. Print a header above output.
- -l. Show login processes waiting for someone to log in.
- -n#. Specify the number of users per line for the -q option.
- -p. Show active processes spawned by init.
- -q. Show just-logged-in usernames.
- -r. Show the system run level.
- -s. Short form of who (no time since last output or pid).
- -u. Show logged-in users.
- -m. Show information only about current terminal in -u format.
- am i. Show information about current terminal (same as -m).
Some examples follow.
# who root console Sep 28 06:13 (:0) pete pts/2 Nov 6 05:23 (java) mark pts/6 Sep 28 06:13 (acorn) # who H NAME LINE TIME root console Sep 28 06:13 (:0) pete pts/2 Nov 6 05:23 (java) mark pts/6 Sep 28 06:13 (acorn) # who q pete root mark # users=3 # who am i pete pts/2 Jan 31 05:24 (java) #
In the first example, who shows all logged-in users. The second example includes a heading. The third example shows all logged-in users in quick format.
The last example shows information about the current user. Note that root is running the who am i command, but that the output shows the user pete. The who command displays which users are logged in, but does not reflect whether any users have su'd to other accounts (including root).
The command who am i is frequently confused with a different command, whoami. The answers given by these two commands are essentially the same unless you have su'd from one account to another. In this situation, the who am i command will display the original logged-in username, while whoami will display the effective (su'd) username.
rwho Command
In environments with the in.rwhod feature enabled, the rwho command shows which users are logged in to all systems on the local network. The syntax of the rwho command is rwho [-a], where the -a option will show only active users (those who have typed in commands in the past hour). An example follows.
# rwho pete grommit:pts/0 Nov 7 05:48 mark wallace:pts/2 Nov 6 05:23 #
In this example, pete is logged into the system grommit, and mark is logged into the system wallace.
WARNING
At large sites, rwho can create significant amounts of network traffic. This is because all systems running the in.rwhod daemon are frequently broadcasting their status to all other systems on the network. You can see why this feature is disabled by default.
rusers Command
In environments with the rusersd feature enabled, the rusers command shows which users are logged in to another system on the local network. The syntax of the rusers command is rusers [-ahilu] hostlist, where hostlist is a list of one or more host names. The options are:
- -a. Give a report for a machine even if no users are logged on.
- -h. Sort alphabetically by host name.
- -i. Sort by idle time.
- -l. Give a longer listing in the style of who(1).
- -u. Sort by number of users.
When the l option is used, the rusers output resembles that of the who command; the output format is:
userid hostname:terminal login date login time idle time login host
Some examples follow.
# rusers -l Sending broadcast for rusersd protocol version 3... pete wallace:pts/2 Jan 31 05:24 7 (java) gsmith wallace:pts/3 Jan 31 05:29 (java) mark grommit:pts/0 Feb 1 04:04 7 (acorn) Sending broadcast for rusersd protocol version 2... #
# rusers Sending broadcast for rusersd protocol version 3... wallace pete gsmith grommit mark Sending broadcast for rusersd protocol version 2... #
In the first example, the rusers -l command lists three users (pete, gsmith, and mark) on two systems (wallace and grommit), in the format resembling that of who. In the second example, the abbreviated rusers output lists the usernames who are logged into each system on the network.
finger Command
The finger command can be used to get information about other users on the system. The syntax of the finger command takes three forms:
finger [-bfhilmpqsw] [username]... finger [-l] [ username@hostname 1 [ @hostname 2 .. .@hostname n]...] finger [-l] [ @hostname 1 [ @hostname 2 .. .@hostname n]...]
In the first form, the available options are:
- -b. Suppress printing the user's home directory and shell in a long format printout.
- -f. Suppress printing the header that is normally printed in a short format printout.
- -h. Suppress printing of the .project file in a long format printout.
- -i. Force "idle" output format, which is similar to short format except that only the login name, terminal, login time, and idle time are printed.
- -l. Force long output format.
- -m. Match arguments only on username (not first or last name).
- -p. Suppress printing of the .plan file in a long format printout.
- -q. Force quick output format, which is similar to short format except that only the login name, terminal, and login time are printed.
- -s. Force short output format.
- -w. Suppress printing the full name in a short format printout.
In the second and third forms, the -l option forces long output format.
Some examples follow.
# finger gsmith Login name: gsmith In real life: Greg Smith Directory: /export/home/gsmith Shell: /bin/sh On since Nov 7 06:18:59 on pts/17 from myclient No unread mail No Plan. # # finger -q gsmith Login TTY When gsmith pts/3 Wed Jan 31 05:29 # # finger mark@grommit [grommit] Login Name TTY Idle When Where pete Mark Foster pts/0 Thu 04:04 wallace # # finger @wallace [wallace] Login Name TTY Idle When Where pete Peter Gregory pts/2 Wed 05:24 myclient gsmith Greg Smith pts/3 1 Wed 05:29 myclient # # finger -l @wallace [wallace] Login name: pete In real life: Peter Gregory Directory: /export/home/pete Shell: /bin/sh On since Jan 31 05:24:14 on pts/2 from myclient Mail last read Thu Jun 29 04:23:10 2000 No Plan.
Login name: gsmith In real life: Greg Smith Directory: /export/home/gsmith Shell: /bin/sh On since Jan 31 05:29:31 on pts/3 from myclient 2 minutes 11 seconds Idle Time No unread mail No Plan. #
In the first example (finger gsmith), the username gsmith is logged in on the same system that executed the finger command. In the next example (finger q gsmith), we see information about username gsmith but in quick format. In the third example (finger mark@grommit), we are querying specifically about the username mark on the system grommit. In the fourth example (finger @wallace), we are looking for short-form information about all users logged into the system wallace. In the last example (finger l @wallace), we see long-form information about users logged into wallace.
In recent years many sites have disabled finger for security reasons. Check with your site administrator to see if this is the case in your organization. If finger is disabled on a system you're trying to reach, you'll get an error message that reads, "[system-name] connect: Connection refused".
Change Password
Root can change any user's account with the passwd command. The format of the passwd command is passwd username options. Allowable options include:
- -d. Deletes the password. Subsequent logins will not prompt for a password.
- -f. Forces the user to change passwords at the next login.
- -l. Locks the account, preventing further logins.
- -n min. Sets the minimum number of days between password changes.
- -w warn. Sets the number of days before password expiration that the user is warned about it.
- -x max. Sets the maximum number of days between password changes.
- -s username. Displays password attributes for username.
- -a. Displays password attributes for all users. Use only with the -s option.
- -h username. Changes the home directory for username.
- -e username. Changes the login shell for username.
- -g username. Changes the gcos-field (full name) for username.
Some examples follow.
# passwd f mark # # passwd s gsmith gsmith PS # # passwd -h gsmith Default values are printed inside of '[]'. To accept the default, type <return>. To have a blank entry, type the word 'none'.
Home Directory [/export/home/gsmith]: /d2/home/gsmith # # passwd e jhamid Old shell: /bin/sh New shell: /bin/csh # $ passwd passwd: Changing password for gsmith Enter login password: ******* passwd(SYSTEM): Sorry: less than 7 days since the last change. Permission denied $ % passwd passwd: Changing password for gsmith Enter login password: ****** New password: ****** Re-enter new password: ****** passwd (SYSTEM): passwd successfully changed for gsmith %
In the first example, the account mark is forced to change passwords at the next login. In the second example, the password status for account gsmith is listed. PS means that the account has a password; NP means no password; and LK means the account is locked. In the third example, the home directory for account gsmith is changed to /d2/home/gsmith. In the fourth example, the default shell for jhamid is changed from /bin/sh to /bin/csh. In the fifth example, a user attempts to change his password but is denied because the minimum number of days between password changes has not elapsed. In the last example, a user successfully changes his password.
Password Complexity
The passwd command also checks the "complexity" of the password that the user entered. By complexity we mean that all of the following rules must be met:
The length of the password must be at least PASSLENGTH characters, where PASSLENGTH is a variable that is defined in the /etc/default/passwd file. The default value is set to 6. Only the first eight characters are significant.
The password must contain at least two lower- or uppercase letters and at least one numeric or special character.
The password must be different from the userid and any reverse or circular shift of the userid. Upper- and lowercase letters are considered equal for this test. For example, user gsmith cannot change his password to GSMITH.
The new and old passwords must differ by at least three characters. Upper- and lowercase letters are considered equal for this test.
Of the characterics listed, only PASSLENGTH can be changed. All of these characteristics can be bypassed if root is changing the password. This is discussed in the next section.
Root and Password Changes
The root user is permitted to change the password for any user. When root changes a user's password, the passwd command does not prompt for the old password. This permits root to "reset" a user's password in circumstances when the user has forgotten his or her password. This also permits root to lock a user's account by changing the user's password to a value that the user is unlikely to guess.
WARNING
The password aging and complexity requirements are bypassed when the root user changes a user's password (or when root changes its own password). The danger of this feature is that a system administrator can set poor-quality passwords. Poor passwords are passwords that are short and/or easily guessed.
Exam Notes
Think About It . . .
Why should users change their own passwords?
First, the user will have a greater chance of remembering the password. This will lead to fewer sticky notes with passwords written down. Next, all of the quality rules about passwords (length, complexity, etc.) are enforced when users change their own passwords (no quality checking is performed when root changes a user's password). Finally, over time the user will have a better understanding of the password quality rules.