• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Tuesday, May 06, 2014

    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


    Follow the below links for more tutorials

    What is the difference/comparison between Unix and Linux ?
    What are the maximum and minimum limits for RHEL 4 vs 5 vs 6 ?
    RAID levels 0, 1, 2, 3, 4, 5, 6, 0+1, 1+0 features explained in detail

    0 comments:

    Post a Comment