Linux Display Date And Time Of Login

How do I display user last login date and time under Linux operating systems?

Linux use the following two files to keep track of user login sessions:

a] /var/run/utmp – List of current login sessions.

b] /var/log/wtmp – List of previous login sessions.

c] /var/log/btmp – List all the bad login attempt.

last command

The last command searches back through the file /var/log/wtmp file and displays a list of all users logged in (and out) since that file was created. Names of users and tty’s can be given, in which case last will show only those entries matching the arguments. Names of ttys can be abbreviated, thus last 0 is the same as last tty0. Type the following command:
last username

Sample outputs:

vivek    pts/3        :0.0             Thu Oct 29 00:46   still logged in   
vivek    pts/0        :0.0             Wed Oct 28 23:14   still logged in   
vivek    pts/2        :0.0             Wed Oct 28 22:12 - 23:11  (00:58)    
vivek    pts/0        :0.0             Wed Oct 28 21:43 - 23:11  (01:27)    
vivek    tty7         :0               Wed Oct 28 21:41   still logged in 

Task: Find Out Who Was Logged In At A Particular Time

To display the state of logins as of the specified time to determine easily who was logged in at a particular time specify that time with -t option and look for “still logged in”.
last -t 20091028231100 username

Task: Show Only Tty Matching Entries

Use the following syntax:
last tty
last tty2
last pts/3

lastb command

The lastb command is the same as last command, except that by default it shows a log of all the bad login attempts, enter:
lastb username
lastb vivek
lastb pts/2

How do I See All Failed Login Count and Other Information?

I recommend configuring PAM and use faillog command display all failed login attempts for given usernames.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts