How to Find User Account Info and Login Details in Linux?


For the sysadmins, it is routine to monitor user details like who are active and who are not, who logged in in last 2 days, which users belong to a given group etc etc. To help these requirements, Linux provides below list of commands which can be used to gather various types of information about the users.

id Command

It gives the id details of users including the group id along with the secondary group IDs and names of a user choosen by the system. But you also ask for a specific user’sdeatils by giving the userid value in the command.

ubuntu@ubuntu:~$ id
ubuntu@ubuntu:~$ id 2112

Running the above code gives us the following result:

uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare)
uid=2112(uname1) gid=3421(uname1) groups=3421(uname1)

groups

It displays the group names the currently logged in user belongs to.

ubuntu@ubuntu:~$ groups

Running the above code gives us the following result −

ubuntu adm cdrom sudo dip plugdev lpadmin sambashare

getnet

This command looks into passed file and gets the user details form there.

ubuntu@ubuntu:~$ getent passwd

Running the above code gives us the following result −

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
……
………

lslogins

The lslogins command displays details of the known users of the system.

ubuntu@ubuntu:~$ lslogins –u

Running the above code gives us the following result −

UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 135 root
1000 ubuntu 70 23:04:25 ubuntu16LTS,,,
2112 uname1 0 storefront
9002 uname4 0 HR

w

It displays the current users logged in to the system and the processes they are running.

ubuntu@ubuntu:~$ w

Running the above code gives us the following result −

08:13:17 up 12:26, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
ubuntu tty7 :0 23:04 12:58m 1:23 0.34s /sbin/upstart –user

Updated on: 03-Jan-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements