How to get information about logins on your Linux system.

Reading information about logins on a Linux system is very useful when you are running a Linux machine. The last command will print information about the last logins on a Linux system.

ubuntu ~ $ last
ubuntu   pts/0        ip-10-8-0-6.ap-s Sun Apr 19 10:25   still logged in
 
wtmp begins Sun Apr 19 10:25:42 2015

Run the lastlog command to print out a list of user accounts and the last time they logged into the system. If they used SSH to connect, the IP address will be listed with their name.

ubuntu ~ $ lastlog
Username         Port     From             Latest
root                                       **Never logged in**
daemon                                     **Never logged in**
bin                                        **Never logged in**
sys                                        **Never logged in**
sync                                       **Never logged in**
games                                      **Never logged in**
man                                        **Never logged in**
lp                                         **Never logged in**
mail                                       **Never logged in**
news                                       **Never logged in**
uucp                                       **Never logged in**
proxy                                      **Never logged in**
www-data                                   **Never logged in**
backup                                     **Never logged in**
list                                       **Never logged in**
irc                                        **Never logged in**
gnats                                      **Never logged in**
nobody                                     **Never logged in**
libuuid                                    **Never logged in**
syslog                                     **Never logged in**
messagebus                                 **Never logged in**
landscape                                  **Never logged in**
sshd                                       **Never logged in**
pollinate                                  **Never logged in**
ubuntu           pts/0    ip-10-8-0-6.ap-s Sun Apr 19 10:25:42 +0000 2015
arma3                                      **Never logged in**
mysql                                      **Never logged in**
colord                                     **Never logged in**
jason                                      **Never logged in**
vaas                                       **Never logged in**

The last command accepts a username as a parameter, the administrator may give a username as a parameter and this will list all logins by that user.

[email protected]:~$ last jason
jason    pts/0        :0.0             Sun Apr 19 22:18   still logged in   
jason    :0           :0               Sun Apr 19 22:13   still logged in   
jason    pts/0        :0.0             Fri Apr 17 22:47 - 23:30  (00:42)    
jason    :0           :0               Fri Apr 17 22:00 - 23:30  (01:29)    
jason    pts/15       :0.0             Thu Apr 16 08:50 - 10:36  (01:45)    
jason    pts/1        :0.0             Thu Apr 16 08:16 - 10:36  (02:20)    
jason    :0           :0               Thu Apr 16 07:56 - down   (02:40)    
jason    pts/0        :0.0             Wed Apr 15 09:47 - 11:33  (01:46)    
jason    :0           :0               Wed Apr 15 09:03 - 11:34  (02:30)    
jason    tty2                          Tue Apr 14 13:26 - down   (00:00)    
jason    pts/0        :0.0             Tue Apr 14 13:09 - 13:26  (00:16)    
jason    :0           :0               Tue Apr 14 10:50 - down   (02:36)    
jason    tty3                          Mon Apr 13 23:09 - down   (00:55)    
jason    tty2                          Mon Apr 13 23:09 - down   (00:55)    
jason    pts/1        :0.0             Mon Apr 13 15:00 - 00:04  (09:04)    
jason    :0           :0               Mon Apr 13 14:58 - 00:04  (09:06)    
jason    pts/1        :0               Mon Apr 13 09:26 - 11:17  (01:50)    
jason    :0           :0               Mon Apr 13 09:04 - 11:17  (02:13)    
jason    pts/3        :0               Sun Apr 12 21:47 - 23:58  (02:11)    
jason    pts/0        :0               Sun Apr 12 21:46 - 23:58  (02:12)    
jason    :0           :0               Sun Apr 12 21:44 - down   (02:13)    
jason    pts/5        :0               Sat Apr 11 10:55 - 14:04  (03:09)    
jason    :0           :0               Sat Apr 11 10:43 - down   (03:20)    
jason    pts/5        :0               Thu Apr  9 13:40 - 13:42  (00:01)    
jason    :0           :0               Thu Apr  9 13:40 - down   (00:02)    
jason    pts/12       :0               Wed Apr  8 09:59 - 09:59  (00:00)    
jason    pts/7        :0               Wed Apr  8 09:55 - 12:00  (02:04)    
jason    :0           :0               Wed Apr  8 09:53 - down   (03:09)    
jason    pts/3        :0               Tue Apr  7 14:09 - 14:09  (00:00)    
jason    pts/3        :0               Tue Apr  7 10:43 - 14:09  (03:25)    
jason    :0           :0               Tue Apr  7 10:17 - down   (04:07)    
jason    pts/1        :0               Sat Apr  4 12:33 - 13:01  (00:27)    
jason    pts/1        :0               Sat Apr  4 12:23 - 12:33  (00:09)    
jason    :0           :0               Sat Apr  4 12:06 - down   (00:54)

The -F parameter will list full times and dates of logins.

[email protected]:~$ last -F jason
jason    pts/0        :0.0             Sun Apr 19 22:18:28 2015   still logged in                      
jason    :0           :0               Sun Apr 19 22:13:08 2015   still logged in                      
jason    pts/0        :0.0             Fri Apr 17 22:47:59 2015 - Fri Apr 17 23:30:34 2015  (00:42)    
jason    :0           :0               Fri Apr 17 22:00:45 2015 - Fri Apr 17 23:30:37 2015  (01:29)    
jason    pts/15       :0.0             Thu Apr 16 08:50:30 2015 - Thu Apr 16 10:36:18 2015  (01:45)    
jason    pts/1        :0.0             Thu Apr 16 08:16:44 2015 - Thu Apr 16 10:36:47 2015  (02:20)    
jason    :0           :0               Thu Apr 16 07:56:31 2015 - down                      (02:40)    
jason    pts/0        :0.0             Wed Apr 15 09:47:13 2015 - Wed Apr 15 11:33:58 2015  (01:46)    
jason    :0           :0               Wed Apr 15 09:03:05 2015 - Wed Apr 15 11:34:03 2015  (02:30)    
jason    tty2                          Tue Apr 14 13:26:07 2015 - down                      (00:00)    
jason    pts/0        :0.0             Tue Apr 14 13:09:53 2015 - Tue Apr 14 13:26:20 2015  (00:16)    
jason    :0           :0               Tue Apr 14 10:50:17 2015 - down                      (02:36)    
jason    tty3                          Mon Apr 13 23:09:34 2015 - down                      (00:55)    
jason    tty2                          Mon Apr 13 23:09:27 2015 - down                      (00:55)    
jason    pts/1        :0.0             Mon Apr 13 15:00:19 2015 - Tue Apr 14 00:04:52 2015  (09:04)    
jason    :0           :0               Mon Apr 13 14:58:19 2015 - Tue Apr 14 00:04:52 2015  (09:06)    
jason    pts/1        :0               Mon Apr 13 09:26:56 2015 - Mon Apr 13 11:17:55 2015  (01:50)    
jason    :0           :0               Mon Apr 13 09:04:54 2015 - Mon Apr 13 11:17:55 2015  (02:13)    
jason    pts/3        :0               Sun Apr 12 21:47:11 2015 - Sun Apr 12 23:58:32 2015  (02:11)    
jason    pts/0        :0               Sun Apr 12 21:46:37 2015 - Sun Apr 12 23:58:38 2015  (02:12)    
jason    :0           :0               Sun Apr 12 21:44:51 2015 - down                      (02:13)    
jason    pts/5        :0               Sat Apr 11 10:55:09 2015 - Sat Apr 11 14:04:14 2015  (03:09)    
jason    :0           :0               Sat Apr 11 10:43:25 2015 - down                      (03:20)    
jason    pts/5        :0               Thu Apr  9 13:40:56 2015 - Thu Apr  9 13:42:51 2015  (00:01)    
jason    :0           :0               Thu Apr  9 13:40:34 2015 - down                      (00:02)    
jason    pts/12       :0               Wed Apr  8 09:59:32 2015 - Wed Apr  8 09:59:45 2015  (00:00)    
jason    pts/7        :0               Wed Apr  8 09:55:25 2015 - Wed Apr  8 12:00:18 2015  (02:04)    
jason    :0           :0               Wed Apr  8 09:53:31 2015 - down                      (03:09)    
jason    pts/3        :0               Tue Apr  7 14:09:26 2015 - Tue Apr  7 14:09:37 2015  (00:00)    
jason    pts/3        :0               Tue Apr  7 10:43:53 2015 - Tue Apr  7 14:09:20 2015  (03:25)    
jason    :0           :0               Tue Apr  7 10:17:31 2015 - down                      (04:07)    
jason    pts/1        :0               Sat Apr  4 12:33:21 2015 - Sat Apr  4 13:01:00 2015  (00:27)    
jason    pts/1        :0               Sat Apr  4 12:23:23 2015 - Sat Apr  4 12:33:10 2015  (00:09)    
jason    :0           :0               Sat Apr  4 12:06:34 2015 - down                      (00:54)

Passing the -x parameter will display all system reboots and runlevel changes.

[email protected]:~$ last -x
jason    pts/0        :0.0             Sun Apr 19 22:18   still logged in   
jason    :0           :0               Sun Apr 19 22:13   still logged in   
runlevel (to lvl 5)   3.19.0-10-generi Sun Apr 19 22:08 - 22:30  (00:22)    
(unknown :0           :0               Sun Apr 19 22:07 - 22:13  (00:05)    
reboot   system boot  3.19.0-10-generi Mon Apr 20 08:06 - 22:30  (-9:-35)   
jason    pts/0        :0.0             Fri Apr 17 22:47 - 23:30  (00:42)    
jason    :0           :0               Fri Apr 17 22:00 - 23:30  (01:29)    
runlevel (to lvl 5)   3.19.0-10-generi Fri Apr 17 21:58 - 22:08 (2+00:09)   
(unknown :0           :0               Fri Apr 17 21:57 - 22:00  (00:03)    
reboot   system boot  3.19.0-10-generi Sat Apr 18 07:56 - 22:30 (1+14:33)   
shutdown system down  3.19.0-10-generi Thu Apr 16 10:36 - 07:56 (1+21:19)   
jason    pts/15       :0.0             Thu Apr 16 08:50 - 10:36  (01:45)    
jason    pts/1        :0.0             Thu Apr 16 08:16 - 10:36  (02:20)    
jason    :0           :0               Thu Apr 16 07:56 - down   (02:40)    
runlevel (to lvl 5)   3.19.0-10-generi Thu Apr 16 07:55 - 10:36  (02:41)    
(unknown :0           :0               Thu Apr 16 07:53 - 07:56  (00:02)    
reboot   system boot  3.19.0-10-generi Thu Apr 16 17:53 - 10:36  (-7:-16)   
shutdown system down  3.19.0-10-generi Wed Apr 15 11:34 - 17:53 (1+06:19)   
jason    pts/0        :0.0             Wed Apr 15 09:47 - 11:33  (01:46)    
jason    :0           :0               Wed Apr 15 09:03 - 11:34  (02:30)    
runlevel (to lvl 5)   3.19.0-10-generi Wed Apr 15 08:46 - 11:34  (02:47)    
(unknown :0           :0               Wed Apr 15 08:45 - 09:03  (00:17)    
reboot   system boot  3.19.0-10-generi Wed Apr 15 18:45 - 11:34  (-7:-10)   
shutdown system down  3.19.0-10-generi Tue Apr 14 13:26 - 18:45 (1+05:18)   
jason    tty2                          Tue Apr 14 13:26 - down   (00:00)    
jason    pts/0        :0.0             Tue Apr 14 13:09 - 13:26  (00:16)    
jason    :0           :0               Tue Apr 14 10:50 - down   (02:36)    
runlevel (to lvl 5)   3.19.0-10-generi Tue Apr 14 10:39 - 13:26  (02:46)    
(unknown :0           :0               Tue Apr 14 10:38 - 10:50  (00:11)    
reboot   system boot  3.19.0-10-generi Tue Apr 14 20:38 - 13:26  (-7:-11)   
shutdown system down  3.19.0-10-generi Tue Apr 14 00:04 - 20:38  (20:33)    
jason    tty3                          Mon Apr 13 23:09 - down   (00:55)    
jason    tty2                          Mon Apr 13 23:09 - down   (00:55)    
jason    pts/1        :0.0             Mon Apr 13 15:00 - 00:04  (09:04)    
runlevel (to lvl 5)   3.19.0-10-generi Mon Apr 13 14:58 - 00:04  (09:06)    
jason    :0           :0               Mon Apr 13 14:58 - 00:04  (09:06)    
(unknown :0           :0               Mon Apr 13 14:57 - 14:58  (00:00)    
reboot   system boot  3.19.0-10-generi Tue Apr 14 00:56 - 00:04  (00:-51)   
shutdown system down  3.19.0-10-generi Mon Apr 13 11:17 - 00:56  (13:38)    
jason    pts/1        :0               Mon Apr 13 09:26 - 11:17  (01:50)    
jason    :0           :0               Mon Apr 13 09:04 - 11:17  (02:13)    
runlevel (to lvl 5)   3.19.0-10-generi Mon Apr 13 08:59 - 11:17  (02:18)    
(unknown :0           :0               Mon Apr 13 08:58 - 09:04  (00:06)    
reboot   system boot  3.19.0-10-generi Mon Apr 13 18:57 - 11:17  (-7:-39)   
shutdown system down  3.19.0-10-generi Sun Apr 12 23:58 - 18:57  (18:59)    
runlevel (to lvl 0)   3.19.0-10-generi Sun Apr 12 23:58 - 23:58  (00:00)    
jason    pts/3        :0               Sun Apr 12 21:47 - 23:58  (02:11)    
jason    pts/0        :0               Sun Apr 12 21:46 - 23:58  (02:12)    
jason    :0           :0               Sun Apr 12 21:44 - down   (02:13)    
(unknown :0           :0               Sun Apr 12 21:43 - 21:44  (00:00)    
runlevel (to lvl 2)   3.19.0-10-generi Sun Apr 12 21:43 - 23:58  (02:15)    
reboot   system boot  3.19.0-10-generi Sun Apr 12 21:43 - 23:58  (02:15)    
shutdown system down  3.19.0-10-generi Sat Apr 11 14:04 - 21:43 (1+07:39)   
runlevel (to lvl 6)   3.19.0-10-generi Sat Apr 11 14:04 - 14:04  (00:00)    
jason    pts/5        :0               Sat Apr 11 10:55 - 14:04  (03:09)    
jason    :0           :0               Sat Apr 11 10:43 - down   (03:20)    
(unknown :0           :0               Sat Apr 11 10:42 - 10:43  (00:00)    
runlevel (to lvl 2)   3.19.0-10-generi Sat Apr 11 10:42 - 14:04  (03:21)    
reboot   system boot  3.19.0-10-generi Sat Apr 11 10:42 - 14:04  (03:21)    
shutdown system down  3.19.0-10-generi Thu Apr  9 13:43 - 10:42 (1+20:59)   
runlevel (to lvl 0)   3.19.0-10-generi Thu Apr  9 13:42 - 13:43  (00:00)    
jason    pts/5        :0               Thu Apr  9 13:40 - 13:42  (00:01)    
jason    :0           :0               Thu Apr  9 13:40 - down   (00:02)    
(unknown :0           :0               Thu Apr  9 13:38 - 13:40  (00:02)    
runlevel (to lvl 2)   3.19.0-10-generi Thu Apr  9 13:37 - 13:42  (00:05)    
reboot   system boot  3.19.0-10-generi Thu Apr  9 13:37 - 13:42  (00:05)    
shutdown system down  3.19.0-10-generi Wed Apr  8 13:03 - 13:37 (1+00:34)   
runlevel (to lvl 6)   3.19.0-10-generi Wed Apr  8 13:03 - 13:03  (00:00)    
jason    pts/12       :0               Wed Apr  8 09:59 - 09:59  (00:00)    
jason    pts/7        :0               Wed Apr  8 09:55 - 12:00  (02:04)    
jason    :0           :0               Wed Apr  8 09:53 - down   (03:09)    
(unknown :0           :0               Wed Apr  8 09:52 - 09:53  (00:00)    
runlevel (to lvl 2)   3.19.0-10-generi Wed Apr  8 09:52 - 13:03  (03:10)    
reboot   system boot  3.19.0-10-generi Wed Apr  8 09:52 - 13:03  (03:10)    
runlevel (to lvl 5)   3.19.0-10-generi Tue Apr  7 14:27 - 09:52  (19:25)    
(unknown :0           :0               Tue Apr  7 14:26 - 14:28  (00:01)    
reboot   system boot  3.19.0-10-generi Wed Apr  8 00:26 - 13:03  (12:37)    
shutdown system down  3.19.0-10-generi Tue Apr  7 14:25 - 00:26  (10:00)    
runlevel (to lvl 6)   3.19.0-10-generi Tue Apr  7 14:25 - 14:25  (00:00)    
jason    pts/3        :0               Tue Apr  7 14:09 - 14:09  (00:00)    
jason    pts/3        :0               Tue Apr  7 10:43 - 14:09  (03:25)    
jason    :0           :0               Tue Apr  7 10:17 - down   (04:07)    
(unknown :0           :0               Tue Apr  7 10:16 - 10:17  (00:00)    
runlevel (to lvl 2)   3.19.0-10-generi Tue Apr  7 10:16 - 14:25  (04:08)    
reboot   system boot  3.19.0-10-generi Tue Apr  7 10:16 - 14:25  (04:08)    
shutdown system down  3.19.0-10-generi Sun Apr  5 15:44 - 10:16 (1+18:31)   
runlevel (to lvl 5)   3.19.0-10-generi Sun Apr  5 15:42 - 15:44  (00:02)    
(unknown :0           :0               Sun Apr  5 15:41 - 15:44  (00:03)    
reboot   system boot  3.19.0-10-generi Mon Apr  6 01:40 - 15:44  (-9:-55)   
shutdown system down  3.19.0-10-generi Sat Apr  4 13:01 - 01:40 (1+13:39)   
runlevel (to lvl 6)   3.19.0-10-generi Sat Apr  4 13:01 - 13:01  (00:00)    
jason    pts/1        :0               Sat Apr  4 12:33 - 13:01  (00:27)    
jason    pts/1        :0               Sat Apr  4 12:23 - 12:33  (00:09)    
jason    :0           :0               Sat Apr  4 12:06 - down   (00:54)    
(unknown :0           :0               Sat Apr  4 12:06 - 12:06  (00:00)    
runlevel (to lvl 2)   3.19.0-10-generi Sat Apr  4 12:06 - 13:01  (00:55)    
reboot   system boot  3.19.0-10-generi Sat Apr  4 12:06 - 13:01  (00:55)    
shutdown system down  3.19.0-10-generi Sat Apr  4 12:05 - 12:06  (00:00)    
runlevel (to lvl 6)   3.19.0-10-generi Sat Apr  4 12:04 - 12:05  (00:00)    
(unknown :0           :0               Sat Apr  4 11:51 - down   (00:13)    
runlevel (to lvl 2)   3.19.0-10-generi Sat Apr  4 11:51 - 12:04  (00:13)    
reboot   system boot  3.19.0-10-generi Sat Apr  4 11:51 - 12:04  (00:13)    
shutdown system down  3.19.0-10-generi Thu Apr  2 08:51 - 11:51 (2+02:59)   
runlevel (to lvl 6)   3.19.0-10-generi Thu Apr  2 08:51 - 08:51  (00:00)    
 
wtmp begins Thu Apr  2 08:51:04 2015

And finally, this is another way to show the most recent login by a certain user.

[email protected]:~$ lastlog -u jason
Username         Port     From             Latest
jason            tty2                      Tue Apr 14 13:26:07 +1000 2015

No comments have been made. Use this form to start the conversation :)

Leave a Reply