This article will show you eleven useful ways to find User Account Info and Login Details onLinux system. Here we’ll describe commands to get a user’s account details, show login details as well as what users are doing on the system.
Read Also: How to Monitor Linux Commands Executed by System Users in Real-time
If you want to add users in Linux, use the useradd utility, and to modify or change any attributes of a already created user account, use the usermod via the command line as explained in the following guides:
We’ll start by looking at commands to find a user’s account information, then proceed to explain commands to view login details.
1. id Command
id is a simple command line utility for displaying a real and effective user and group IDs as follows.
$ id linuxtechexpert uid=1000(linuxtechexpert) gid=1000(linuxtechexpert) groups=1000(linuxtechexpert),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),130(sambashare)
2. groups Command
groups command is used to show all the groups a user belongs to like this.
$ groups linuxtechexpert linuxtechexpert : linuxtechexpert adm cdrom sudo dip plugdev lpadmin sambashare
3. finger Command
finger command is used to search information about a user on Linux. It doesn’t come per-installed on many Linux systems.
To install it on your system, run this command on the terminal.
$ sudo apt install finger #Debian/Ubuntu $ sudo yum install finger #RHEL/CentOS $ sudo dnf install finger #Fedora 22+
It shows a user’s real name; home directory; shell; login: name, time; and so much more as below.
$ finger linuxtechexpert Login: linuxtechexpert Name: LinuxtechExperyt Directory: /home/linuxtechexpert Shell: /bin/bash On since Fri Sep 22 10:39 (IST) on tty8 from :0 2 hours 1 minute idle No mail. No Plan.
4. getent Command
getent is a command line utility for fetching entries from Name Service Switch (NSS) libraries from a specific system database.
To get a user’s account details, use the passwd database and the username as follows.
$ getent passwd linuxtechexpert linuxtechexpert:x:1000:1000:LinuxtechExpert,,,:/home/linuxtechexpert:/bin/bash
5. grep Command
grep command is a powerful pattern searching tool available on most if not all Linus systems. You can use it to find information about a specific user from the system accounts file: /etc/passwd as shown below.
$ grep -i tecmint /etc/passwd linuxtechexpert:x:1000:1000:LinuxtechExpert,,,:/home/linuxtechexpert:/bin/bash
6. lslogins Command
lslogins command shows information about known users in the system, the
-u flag only displays user accounts.
$ lslogins -u UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 144 root 1000 linuxtechexpert 70 10:39:07 LinuxtechExpert,,, 1001 aaronkilik 0 1002 john 0 John Doo
7. users Command
users command shows the usernames of all users currently logged on the system like so.
$ users linuxtechexpert aaron
8. who Command
who command is used to display users who are logged on the system, including the terminals they are connecting from.
$ who -u linuxtechexpert tty8 2017-09-22 10:39 02:09 2067 (:0)
9. w Command
w command shows all users who are logged on the system and what they are doing.
$ w 12:46:54 up 2:10, 1 user, load average: 0.34, 0.44, 0.57 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT linuxtechexpert tty8 :0 10:39 2:10m 4:43 0.46s cinnamon-sessio
10. last or lastb commands
last/lastb commands displays a list of last logged in users on the system.
$ last OR $ last -a #show hostname on the last column
List of Last Logged Users
linuxtechexpert tty8 Fri Sep 22 10:39 gone - no logout :0 reboot system boot Fri Sep 22 10:36 still running 4.4.0-21-generic linuxtechexpert tty8 Thu Sep 21 10:44 - down (06:56) :0 reboot system boot Thu Sep 21 10:42 - 17:40 (06:58) 4.4.0-21-generic linuxtechexpert tty8 Wed Sep 20 10:19 - down (06:50) :0 reboot system boot Wed Sep 20 10:17 - 17:10 (06:52) 4.4.0-21-generic linuxtechexpert pts/14 Tue Sep 19 15:15 - 15:16 (00:00) tmux(14160).%146 linuxtechexpert pts/13 Tue Sep 19 15:15 - 15:16 (00:00) tmux(14160).%145 ...
To show all the users who were present at a specified time, use the
-p option as follows.
$ last -ap now linuxtechexpert tty8 Fri Sep 22 10:39 gone - no logout :0 reboot system boot Fri Sep 22 10:36 still running 4.4.0-21-generic wtmp begins Fri Sep 1 16:23:02 2017
11. lastlog Command
lastlog command is used to find the details of a recent login of all users or of a given user as follows.
$ lastlog OR $ lastlog -u linuxtechexpert #show lastlog records for specific user linuxtechexpert
Records of Recent Logged Users
Username Port From Latest root **Never logged in** kernoops **Never logged in** pulse **Never logged in** rtkit **Never logged in** saned **Never logged in** usbmux **Never logged in** mdm **Never logged in** linuxtechexpert pts/1 127.0.0.1 Fri Jan 6 16:50:22 +0530 2017 ..
That’s it! If you know any other command-line trick or command to view user account details do share with us.
You’ll find these related article so useful:
- How to Manage Users and Groups in Linux
- How to Delete User Accounts with Home Directory in Linux
- 3 Ways to Change Default User Shell in Linux
- How to Block or Disable User Logins in Linux
In this article, we’ve explained various ways to find information about users and login details on a Linux system. You can ask any questions or share your thoughts via the feedback form below.