Linux provides some commands to view the user: login status, login record, login attempt log, user last login log and so on.

Show the Logged in Users and Their Activities

With the w command, we can see who is currently logged in and what they are doing.

Here are some common options for w command:

Option Meaning
-h or ‑‑no-header Output without header.
-s or ‑‑short Output short format.
-f or ‑‑form Output without form column.
-i or ‑‑ip-addr Output IP address instead of hostname.
1
w
img

Output the users and their activities

Show Without the Header

With the -h option, we can view only the content without displaying the title:

1
w -h    # This equivalent to w --no-header
img

Output without the header

Show the Short Format

With the -s option, we can view only the output in a short format:

1
w -s    # This equivalent to w --short
img

Output the short format

Show Without the Form Column

With the -f option, we can view only the output other than the form column:

1
w -f    # This equivalent to w --form
img

Output without the form column

Show the IP Address Instead of Hostname

With the -i option, we can view the ip address instead of the hostname:

1
w -i    # This equivalent to w --ip-addr
img

Output IP address instead of hostname

Show Users Login Records

With the last command, we can see users’ login records.

Here are some common options for last command:

Option Meaning
-n num or ‑‑lines num Output num of lines.
-x or ‑‑more-records Output runlevel changes, shutdowns records as well.
-a or ‑‑all-records Output hostname in the last column.
-i or ‑‑ip-address Output IP address instead of hostname.
-w or ‑‑wide Output all the columns of the records.
1
last
img

Output users' login records

Number of Rows to Show

With the -n or ‑‑lines option, we can specify the number of rows to output for the log-in records:

1
last -n 10    # This is equivalent to last -10 or last --lines 10
img

Output ten lines of records

Show Log in Failed Record

The options for the lastb command are similar to those for the last command.

1
lastb

Displays Ten Lines of Login Failure Records

With the -n or ‑‑lines option, we can specify the number of rows to output for the log-in failed records:

1
lastb -n 10    # this is equivalent to lastb -10 or lastb --lines 10
img

Output ten lines of login failed records.

We can see from the screenshot that someone is trying to log on to my server.

Show the Last Login Record of Users

We can use the lastlog command to display the record of all or a user’s last login:

1
lastlog
img

Output all the users' last login records.

Show the Record of a Specific User

With the -u option, we can view only the last login record of a specified user:

1
lastlog -u root
img

Output all the users' last login records.

References 20 User information, W(1), LAST, LASTB(1), LASTLOG(8)

Buy me a coffeeBuy me a coffee