pages

Thursday, January 26, 2017

6 commands to list the logged in users in Linux

How will you check the complete list of logged in users either current or all those attempts which have been made to connect your machine by any user and the status of connection

Here are 6 commands which I use to view the users who have logged in recently or are currently logged in to any particular Linux machine

Method 1

users: This command print the user names of users currently logged in to the current host without showing any much information about the source, login time or any other relevant detail

# users
deepak ruchi aman rahul ramandeep


Method 2

last: 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. Names of users and tty's can be given, in which case last will show only those entries matching the arguments.

# last -a
deepak   pts/3        Tue Oct 16 18:01 - 18:01  (00:00)     10.10.10.30
root     pts/2        Tue Oct 16 17:51   still logged in    10.10.10.30
root     pts/1        Tue Oct 16 14:29 - 18:03  (03:34)     10.10.10.30
root     pts/3        Tue Oct 16 11:10 - 13:11  (02:00)     10.10.10.30
root     pts/1        Mon Oct 15 20:30 - 13:21  (16:51)     10.10.10.30
root     pts/3        Mon Oct 15 18:02 - 18:37  (00:34)     10.10.10.30
root     pts/1        Mon Oct 15 15:23 - 18:34  (03:11)     10.10.10.30
root     pts/1        Mon Oct 15 10:45 - 15:22  (04:36)     10.10.10.30
root     pts/2        Fri Oct 12 18:34 - 15:53 (3+21:19)    :2.0
root     pts/1        Fri Oct 12 18:07 - 19:34  (01:27)     10.10.10.30
root     pts/0        Fri Oct 12 17:57   still logged in    :0.0
root     tty1         Fri Oct 12 17:56   still logged in    :0

reboot   system boot  Fri Oct 12 17:44 - 18:03 (4+00:19)    2.6.32-220.el6.i686

Method 3

secure file: This file contains the logs of all the attempts made for login to your machine with authentication reports

less /var/log/secure
Oct 16 18:01:12 localhost unix_chkpwd[3503]: password check failed for user (deepak)
Oct 16 18:01:14 localhost sshd[3501]: Failed password for deepak from 10.10.10.30 port 2326 ssh2
Oct 16 18:01:21 localhost passwd: pam_unix(passwd:chauthtok): password changed for deepak
Oct 16 18:01:21 localhost passwd: gkr-pam: couldn't update the 'login' keyring password: no old password was entered
Oct 16 18:01:24 localhost sshd[3501]: Accepted password for deepak from 10.10.10.30 port 2326 ssh2
Oct 16 18:01:24 localhost sshd[3501]: pam_unix(sshd:session): session opened for user deepak by (uid=0)
Oct 16 18:01:31 localhost sshd[3501]: pam_unix(sshd:session): session closed for user deepak

Method 4

finger: If no arguments are specified, finger will print an entry for each user currently logged into the system.

# finger
Login     Name       Tty      Idle  Login Time   Office      Office Phone
deepak               pts/3          Oct 16 18:01 (10.10.10.30)
root      root       tty1       4d  Oct 12 17:56 (:0)
root      root       pts/0    6:51  Oct 12 17:57 (:0.0)
root      root       pts/1    2:08  Oct 16 14:29 (10.10.10.30)
root      root       pts/2          Oct 16 17:51 (10.10.10.30)

Method 5

who: This command shows currently logged in users with time details

# who -u
root     tty1         2012-10-12 17:56  old         1960 (:0)
root     pts/0        2012-10-12 17:57 06:51        2376 (:0.0)
root     pts/1        2012-10-16 14:29 02:09        3094  (10.10.10.30)
root     pts/2        2012-10-16 17:51   .          3454 (10.10.10.30)

Method 6

whoami: Print the user name associated with the current effective user ID

# whoami
root

22 comments:

  1. The explanation of those 6 methods is so amazing and very interesting. Thanks for posting please do keep updating...
    Best Online Software Training Institute | Unix Linux Training

    ReplyDelete

  2. Hi there colleagues, fastidious article and fastidious arguments commented at this place, I am truly enjoying by these. outlook 365 login

    ReplyDelete
  3. Very Clear Explanation. Thank you to share this
    Regards,
    PHP Training Institute in Chennai

    ReplyDelete
  4. You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
    Spoken English in Chennai
    Best Spoken English Class in Chennai
    Spoken English in Chennai
    Best Spoken English Class in Chennai
    best spoken english classes in bangalore
    spoken english in bangalore

    ReplyDelete
  5. You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
    best spoken english institute in coimbatore
    spoken english institute in coimbatore
    spoken english course in coimbatore
    best spoken english class in madurai
    best spoken english center in madurai
    Best Spoken English Classes in Chennai
    Spoken English Classes in Chennai

    ReplyDelete


  6. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing the information .Hope more posts from you .I also want to share about best linux online training in recent times also and linux training

    ReplyDelete
  7. I'm very pleased to uncover this web site. I want to to thank you for your time due to this fantastic read!! I definitely loved every little bit of tech it and i also have you bookmarked to look at new information in your site.

    ReplyDelete
  8. Check Latest Updates about your Universities Results. Timetable-Result.com This Site helps to clear your all query.
    BA Final Year Exam result 2020
    BCom 3rd semester Exam result 2020

    ReplyDelete
  9. If you might be purchasing your house, our payment calculator allows you to test down payment and amortization scenarios, and compare variable and fixed mortgage rates. mortgage payment calculator canada Nicole is a home financing broker who works with you, whether you might be purchasing, renovating, looking to be free from debt, or investing. mortgage payment calculator canada

    ReplyDelete
  10. CEA Aviation is seeing an incredible new turn of events in India, with unparalleled student and instructor enrollments, to the point that the Top 10 flight school in delhi is now offering DGCA Ground Classes in India. Within the confines of our sector, CEA Aviation has established links with a collection of air transportation associations to ensure that students approach perplexing workplaces and receive work aid with requests for astounding general information.

    ReplyDelete
  11. I truly awed after read this content. Do you want to improve your language skills but find it difficult to attend traditional tuition classes. Enroll in Ziyyara’s online English tuition classes today and get a chance for a free demo.
    For more info visit Online English Tuition

    ReplyDelete
  12. Nice blog was really feeling good to read it. Thanks for this information. Ziyyara Edutech’s private tuition classes for Class 11 provide comprehensive and personalized learning experiences, tailored specifically to meet the needs of Class 11 students.
    For more info Contact us: +91-9654271931, +971-505593798 or visit online tutoring sites for class 11

    ReplyDelete
  13. Nice blog. Thanks for sharing such an informative and useful post.
    Linux course in Pune

    ReplyDelete