- How to see users currently logged in to Linux
- Method-1: Checking logged-in users with ‘w’ command
- Method-2: Identifying who is Logged-in using ‘who’ command
- Method-3: How to see Logged in users with ‘whoami’ command
- Method-4: Using users command
- Method-5: Show currently logged-in users with ‘finger’ command
- Bonus Tips
- Bonus Tips-1: How to show current logged-in users with ‘last’ command
- Bonus Tips-2: Manual Way to check who’s logged-in
- Over to You
- 12 Ways to Find User Account Info and Login Details in Linux
- 1. id Command – Show User and Group IDs
- 2. groups Command – View User Group Memberships
- 3. finger Command – Show User Information
- 4. getent Command – Fetch User Info from System Database
- 5. grep Command – Search for Patterns or Specific Text in Files
- 6. lslogins Command – Display User Information in Linux
- 7. users Command – List Current Logged-In Users on Linux
- 8. who Command – Show Information Of Currently Logged-In Users
- 9. w Command – Show Currently Logged-In User Activity
- 10. last Command – Show Most Recent Login Session
- 11. lastb Command – Show Failed Login Attempts
- 12. lastlog Command – List User Login Information
How to see users currently logged in to Linux
Linux is a multi-user operating system that allows multiple users to access the system at the same time.
As a Linux system administrator, you have to check who are logged into the system before starting to work on any issues, especially when you have a team members spread across multiple locations. Because, if multiple users are making the changes in the same configuration file, it may create additional problems.
So, make sure nobody is currently working on the issue before you take it up. To avoid these things, we need to check who all are logged into the system and what are they doing.
In this tutorial, we will show you how to check the current logged-in users with several commands in Linux.
Knowing more than one command to find the same information will not hurt you, and do not hesitate to check the alternate options.
Method-1: Checking logged-in users with ‘w’ command
‘w command’ shows who are logged-in and what are they doing. It displays information about current users on the machine by reading the file /var/run/utmp , and their processes /proc .
w command output comes with header information, which displays system activity such as current time, system up time, how many users are currently logged-in, and the system load (which averages for the past 1, 5, and 15 minutes)
w command contains the following values:
login user name, tty number, remote host, user’s login time, idle time, JCPU (time used by all processes attached to the tty), PCPU (time used by the current process), and which commands are currently being executed by the users. Please see below:
# w 17:13:34 up 1:52, 1 user, load average: 0.11, 0.18, 0.15 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 203.99.204.108 15:22 6.00s 0.18s 0.00s w
Method-2: Identifying who is Logged-in using ‘who’ command
‘who command’ shows information about users who are currently logged in. It uses ‘/var/run/utmp’ & ‘/var/log/wtmp’ files to get those details.
- /var/run/utmp: It contains information about the users who are currently logged onto the system. Who command is used to fetch the information from the file.
- /var/log/wtmp: It contains historical utmp. It keeps the users login and logout history. The last command uses this file to display the information.
who command output contains the following values such as login user name, tty number, date & time, and remote host.
# who root pts/0 2017-05-31 15:22 (203.99.204.108)
Method-3: How to see Logged in users with ‘whoami’ command
whoami is basically the concatenation of the strings “who”,”am”,”i” as whoami. It displays the username of the current user. It’s similar to running the id command with the options -un as shown below:
Also, when you use whoami with space (who am i) that will give you a different output. It will display more details compared to whoami command as shown below:
$ who am i daygeek pts/1 2019-06-17 22:01 (192.168.1.6)
“id” command prints user and group information for a specified username, but we can add -un option with the “id” command to display all the currently logged-in users as shown below:
Method-4: Using users command
‘users command’ prints the usernames of users currently logged in to the current host. It uses /var/run/utmp & /var/log/wtmp files to get the details as shown below:
Method-5: Show currently logged-in users with ‘finger’ command
‘finger’ is a utility, which allows users to see the information about system users (login name, home directory, name, how long they’ve been logged in to the system, etc.).
Finger utility is available in all major Linux distributions, but it doesn’t come installed by default. Use distribution package manager to install “finger” on your system.
$ finger Login Name Tty Idle Login Time Office Office Phone magi daygeek tty7 7 Jun 1 16:05 (203.99.204.108)
Bonus Tips
Additionally, you can use the following methods to identify who all are logged-in on your system:
Bonus Tips-1: How to show current logged-in users with ‘last’ command
‘last command’ shows a list of last logged in users by searching the data from /var/log/wtmp file. Also, it shows the system reboot information.
“last” command output contains login user name, tty number, remote host, date, login time, logout time, and the total duration (working time).
Run the following command to show who all logged-in today. Also, you can check who’s currently logged in by filtering with the “still logged in” string.
# last -p today linuxgee tty2 tty2 Thu Mar 4 14:27 gone - no logout linuxgee : : Thu Mar 4 14:27 gone - no logout
Bonus Tips-2: Manual Way to check who’s logged-in
Last but not the least, we can get a list of logged in users on Linux machine manually by using less commands or more commands or head command or tail command, followed by the log file location.
User authentication logs are located @ /var/log/secure for RHEL based systems & /var/log/auth.log for Debian based systems.
$ head -5 /var/log/auth.log Jun 1 16:05:01 daygeek CRON[1944]: pam_unix(cron:session): session opened for user root by (uid=0) Jun 1 16:05:01 daygeek CRON[1944]: pam_unix(cron:session): session closed for user root Jun 1 16:05:44 daygeek lightdm: pam_unix(lightdm-greeter:session): session closed for user lightdm Jun 1 16:05:44 daygeek lightdm: pam_unix(lightdm:session): session opened for user magi by (uid=0) Jun 1 16:05:44 daygeek systemd: pam_unix(systemd-user:session): session opened for user magi by (uid=0)
Over to You
In this guide, you learnt how to find out who all are currently logged-in on your Linux system employing different commands.
If you found this article helpful, please do share with your friends and spread the knowledge. Please feel free to comment below if you have any queries/concerns. We will get back to you as soon as we can. Happy learning!
12 Ways to Find User Account Info and Login Details in Linux
This article will show you useful ways to find information about users on a Linux system. Here we’ll describe commands to get a user’s account details, show login details as well what users are doing on the system.
If you want to add or create users in Linux, use the useradd command, and to modify or change any attributes of an already created user account, use the usermod command via the command line.
You might also like:
We’ll start by looking at 12 useful commands to find a user’s account information, then proceed to explain commands to view login details in the Linux system.
1. id Command – Show User and Group IDs
The id is a simple command line utility for displaying a real and effective user and group IDs identity information for the current user or specified user.
2. groups Command – View User Group Memberships
The groups command is used to display the group memberships for a user. It lists all the groups that a user belongs to, including both primary and supplementary groups.
3. finger Command – Show User Information
The finger command is used to search for information about a user on Linux, which includes detailed information about a specific user or a list of users, including their login name, real name, terminal, idle time, login time, and other relevant details.
The finger command doesn’t come pre-installed on many Linux distributions, you need to install it using your default package manager as shown.
$ sudo apt install finger [On Debian, Ubuntu and Mint] $ sudo yum install finger [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/finger [On Gentoo Linux] $ sudo apk add finger [On Alpine Linux] $ sudo pacman -S finger [On Arch Linux] $ sudo zypper install finger [On OpenSUSE]
It shows a user’s real name; home directory; shell; login: name, time; and so much more as shown below.
4. getent Command – Fetch User Info from System Database
The getent command is used to retrieve information from various databases, including the system user and group databases. It can be used to retrieve information about users, groups, hosts, networks, protocols, and other system entities that are stored in database files like /etc/passwd, /etc/group, /etc/hosts, etc.
To get a user’s account details, use the passwd database and the username as follows.
5. grep Command – Search for Patterns or Specific Text in Files
The grep command is a powerful command used to search for patterns or specific text in files. It allows you to filter and extract lines from text based on matching patterns. The name “grep” stands for “Global Regular Expression Print“.
You might also like:
You can use grep to find information about a specific user from the system accounts file: /etc/passwd as shown below.
6. lslogins Command – Display User Information in Linux
The lslogins command shows information about known users in the system, which typically includes details such as the username, UID (User ID), GID (Group ID), home directory, shell, last login time, and more, depending on the options used and the system configuration.
$ lslogins -u tecmint $ lslogins -u
7. users Command – List Current Logged-In Users on Linux
The users command is used to display the list of currently logged-in users on the Linux system.
8. who Command – Show Information Of Currently Logged-In Users
The who command is used to display users who are logged on to the system, including the username, terminal, login time, and remote host from which the user is logged in.
9. w Command – Show Currently Logged-In User Activity
The w command shows a summary of the currently logged-in users and their activity, which displays the login session, including the username, terminal, login time, idle time, JCPU (total CPU time used by all processes), PCPU (CPU time used by the current process), and the command or process running on the terminal.
10. last Command – Show Most Recent Login Session
The last command displays a list of the most recent login sessions, which includes information about the users who have logged in, their login times, and the terminals or remote hosts they used for login.
To show all the users who were present at a specified time, use the -p option as follows.
11. lastb Command – Show Failed Login Attempts
The lastb command is used to display a list of the last failed login attempts on the system. It reads from the system log file that records failed login attempts, typically stored in /var/log/btmp.
12. lastlog Command – List User Login Information
lastlog command is used to find the details of the most recent login information for all users or a specific user on the system, which provides details about the last login time and location for each user.
$ lastlog OR $ lastlog -u tecmint
That’s it! If you know any other command-line trick or command to view user account details do share with us.
You might also like:
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.