Logged in User Information
Linux Tips by Burleson Consulting
To get a quick count of how
many users are on the system we can use the uptime command.
22:41:39 up 2:33, 2 users, load average: 0.00, 0.00,
We also see some other useful information here, like the
current system time, the amount of time since last startup and the load
average. The load average here is exactly the same as we saw in the top command
we looked at earlier.
For more detailed information about each logged in user,
the w command can be used. The w command also shows the same information uptime
22:42:14 up 2:34, 2 users, load average: 0.00, 0.00,
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
terry :0 20:10 ?xdm? 5:24 1.49s
terry pts/1 22:22 0.00s 0.24s 0.04s /usr/sbin/sshd
Here we see the user name, what terminal they are
connected through (TTY), when they logged in (LOGIN@), how long since they last
did something (IDLE), the amount of CPU time used by all this session's
processes (JCPU), the amount used by the current process (PCPU) and what the
user is currently executing (WHAT).
who is another command which can be used to show who is
logged on the system. It provides a bit less detail than w.
terry :0 Oct 4 20:10
terry pts/1 Oct 4 22:22 (172.16.10.102)
The who command does tell us where the user has
connected from which may be useful. It may show an IP address as above or a
To also see the PID of each logged on user, the -u
option can be added to the who command.
$ who Ėu
terry :0 Oct 4 20:10 ?
terry pts/1 Oct 4 22:22 . 4176
The process ID for the user's main session is now shown
as the second to last column.
Who Am I?
Sometimes it is useful to check who we are currently
logged in as. To do that we use the whoami command.
As you can see, the whoami command just returns the
username of who we're logged in as. This becomes invaluable when we start
switching users like we'll see in the next section.
Switch to a Different User
It is often necessary to switch from one user identity
to another. For instance, the administrator may want to switch from a regular
user login to the root logon in order to set up a new directory structure. In
this example, the userís regular user login ID is terry. Instead of logging off
as terry and then logging on as root, the su (substitute user) command
facilitates an easy switch.
Here we use the whoami command to show that we're
currently logged in as terry, and then we use the su command to temporarily
become root. When we're done working as root we type exit to exit root's shell
and go back to being terry. You may also notice the prompt changed from a $ to
a #. This may not always be the case, but it's a good hint that if your prompt
is a # you are probably running as root.
As with other commands, the su command has a number of
available options, but one of the most useful ones is the - option. This option
essentially logs the user into a new shell as the specified user with the
specified userís profile. Another helpful option is the -c option which allows
the user that is logged in to run a single command as the specified user.
Without using the Ė option, the current profile is maintained when switching
users and the environment variables, such as path for locating executables,
Unless you are logged in as root, the system will ask
for a password when an attempt to switch users is made. As root you can su at
will and assume the identity of any user on the system. This is another reason
you don't want just anybody having the root password.
This is an excerpt from "Easy
Linux Commands" by Linux guru Jon Emmons. You can purchase it for only
$19.95 (30%-off) at