47. User Management - Login Details & Record
Contents
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 ‑‑from | Output without from column. |
-i or ‑‑ip-addr | Output IP address instead of hostname. |
|
|
Show Without the Header
With the -h option, we can view only the content without displaying the title:
|
|
Show the Short Format
With the -s option, we can view only the output in a short format:
|
|
Show Without the From Column
With the -f option, we can view only the output other than the from column:
|
|
Show the IP Address Instead of Hostname
With the -i option, we can view the ip address instead of the 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. |
|
|
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:
|
|
Show Log in Failed Record
The options for the lastb command are similar to those for the last command.
|
|
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:
|
|
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:
|
|
Show the Record of a Specific User
With the -u option, we can view only the last login record of a specified user:
|
|
References 20 User information, W(1), LAST, LASTB(1), LASTLOG(8)
Author Dong Chen
LastMod Tue Mar 19 2019