In this lesson,
you're going to learn how to search
for more about the identities and activities
of each account on your system.
There are several ways to gather information
about user accounts and group memberships
that you might find useful
for troubleshooting your access problems.
In addition to this, there's multiple ways of identifying
what users might currently be logged in to a system.
By understanding how to run these commands,
you're going to be able to answer questions
that your users might have.
The first command we're going to talk about
is the whoami command.
This is used to display the username
with which you're currently logged in to a system.
Sometimes, you may need to log in to a system
and switch amongst different users,
and you may not be sure anymore
which user you're currently logged in as.
When this occurs, just enter the whoami command,
and you'll verify your current username.
Many Linux distributions will show the username
of the currently logged in user at your command prompt too,
so you wouldn't even need to use this command,
but a lot of them don't, and so whoami is really helpful.
If you're logged in as the root user for example,
you're going to see your command prompt turn
into a hashtag or pound sign.
If you're logged in as a standard user though,
you're going to see a dollar sign character
as your command prompt.
The next command we have is the who command.
Now, the who command is used to determine the details
of the user who is currently logged in
to a particular system.
The output of the who command includes the username,
the name of the system from which the user is connected,
and the date and time the user's been connected since.
The proper way for accessing this command and using it
is by typing who and then the options at the command prompt.
The -u option can be used to show how long users
have been idle.
This means how long have they been connected,
but haven't been doing anything.
Now, if you see dot here,
this indicates the user was acted up until the last minute,
if you see old here, this indicates the users
have been inactive for over 24 hours,
and anything in between two minutes
and 23 hours and 59 minutes
will show the exact length of time that they have been idle.
Now, the am I option, entered as who am i,
will display information only for the user
who ran the command.
Another command we have is simply known as w.
The w command is primarily used to display the details
of users who are currently logged in to a system
and their associated transactions.
The first line of the output displays the status
of the system,
the second line of the output displays a table
with the first column listing the users logged in
to the system,
and the last column indicating the current activities
of the users.
The remaining columns of the table
will show different attributes associated with the users.
To use the w command,
simply enter w, options, and the username.
The last command is going to display the history
of the user login and logout actions,
along with the actual time and date.
It also has options to enable you to filter users
who've logged in through a specific terminal.
For example, last 1 will display the details
of users who logged in through the first terminal.
The last command will retrieve information
from the /var/log/wtmp file.
You can access the last command
by entering last and then options.
If you're trying to figure out what commands
were run recently on a given system,
your last command is really going to be useful to you here,
this is really helpful during instant responses too.
The id command is our next one.
The id command is used to display the user ID or UID
and the group ID or GID for a given user.
Entering the command with no options
will display information about the user
who is currently logged in.
You could also specify a username as one of the options
to display the ID information about a particular user.
The proper way to use the id command
is to enter id, the options, and the username.