How to check last login time for users in Linux

There are few commands which you can use to get a list of last logged in users with time details
 

Command 1

last - show listing of last logged in users
Description
This command searches  back through the file /var/log/wtmp (or the file designated by the -f flag) and displays  a  list  of  all  users logged in (and out) since that file was created.
Examples
To view last login time of all the users

$ last
deepak pts/7        server1.example Mon May  5 14:36   still logged in
deepak pts/5        server1.example Mon May  5 14:34   still logged in
deepak pts/7        server1.example Sat May  3 16:20 - 17:21  (01:01)
deepak pts/5        server1.example Sat May  3 16:17 - 17:21  (01:04)
deepak pts/5        server1.example Fri May  2 15:34 - 17:52  (02:17)
deepak pts/5        server1.example Sun Apr 27 23:48 - 07:25 (1+07:37)
root   pts/5        main.test       Sun Apr 27 04:18 - 04:20  (00:02)
rahul  pts/11       server1.example Sat Apr 26 06:25 - 17:16  (10:51)
rahul  pts/10       server1.example Sat Apr 26 06:20 - 17:16  (10:56)

To view the last login time of specific user
 
Syntax

$ last username
$ last deepak
deepak pts/7        server1.example Mon May  5 14:36   still logged in
deepak pts/5        server1.example Mon May  5 14:34   still logged in
deepak pts/7        server1.example Sat May  3 16:20 - 17:21  (01:01)
deepak pts/5        server1.example Sat May  3 16:17 - 17:21  (01:04)

To view the ip address details of the source machine

$ last deepak -i
deepak pts/7        192.168.0.100   Mon May  5 14:36   still logged in
deepak pts/5        192.168.0.100   Mon May  5 14:34   still logged in
deepak pts/7        192.168.0.100   Sat May  3 16:20 - 17:21  (01:01)
deepak pts/5        192.168.0.100   Sat May  3 16:17 - 17:21  (01:04)

 
 

Command 2

lastlog - reports the most recent login of all users or of a given user
 
Description
lastlog formats and prints the contents of the last login log /var/log/lastlog file. The login-name, port, and last login time will be printed. The default (no flags) causes lastlog entries to be printed, sorted by their order in /etc/passwd.
 
Example
To view last login time of deepak

$ lastlog -u deepak
Username         Port     From             Latest
deepak         pts/7    server1.example Mon May  5 14:36:52 -0400 2014

 
Related Articles
10 practical examples to use USERADD command in linux
How to create user without useradd command in Linux
How to give normal user root privileges using sudo in Linux/Unix
How to give permission to user to run some commands in Linux