Posted: . At: 11:57 AM. This was 3 years ago. Post ID: 14856
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Very useful Linux tips for getting information on current logins.


There are many ways to get detailed information on known users on your Linux system. The lslogins command is therefore very useful for listing all usable login accounts.

The below example will list all user accounts including the root account. This might be disabled on an Ubuntu system, but it is worth listing it anyway.

jason@jason-Lenovo-H50-55:~/.steam/steamcmd/arma3$ lslogins | awk '{if($1>999 && $1<2000 || $1 == 0)print $1,$2,$5}'
0 root
1000 jason jason,,,

The users command will list all currently logged in users.

jason@jason-Lenovo-H50-55:~/.steam/steamcmd/arma3$ users
jason

Use the w command to list all currently logged in users and what they are up to.

jason@jason-Lenovo-H50-55:~/.steam/steamcmd/arma3$ w
 10:04:55 up  3:21,  1 user,  load average: 0.29, 0.38, 0.36
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
jason    pts/0    192.168.1.2      06:44    0.00s  1:22m  0.00s w

This shows that the user is currently on the pts/0 terminal and is logged in from the IP address 192.168.1.2.

This is another way to list all users that can actually log in.

jason@jason-Lenovo-H50-55:~/.steam/steamcmd/arma3$ sudo awk -F':' '$2 ~ "\$" {print $1}' /etc/shadow
[sudo] password for jason:
jason

This one-liner will get the date of the last password change on your account.

jason@jason-Lenovo-H50-55:~$ sudo passwd -Sa | grep $LOGNAME | awk '{print $3}'
08/31/2020

These simple commands should be very useful to any Linux administrator.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.