- 6 commands to list the logged in users in Linux
- Method 3
- Method 4
- Method 5
- Method 6
- How to see Logged in Users in Linux
- 4 Commands to see logged users on Linux
- 1. Use w command to see logged in users in Linux
- 2. Check who is logged in with who command
- 3. Just get logged in users with users command
- 4. Using finger command to see logged in users
- Bonus Tip: see who logged on your system since last reboot
- Who Command in Linux
- Prerequisites
- Who Command in Linux
- Syntax
- How to Use Who Command in Linux
- Who Command Examples
- Display Header
- Display System Boot Time
- Display Current Run Level
- Display List and Number of Current Users
- Display All Information of Users Logged In
- Display List of Dead Processes
- Who Command Options
- Conclusion
6 commands to list the logged in users in Linux
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
# 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
How to see Logged in Users in Linux
Check who is logged in your Linux system with these simple commands. You can also get additional information about logged in users such as their log in time.
Have you ever been curious about who is logged in to your Linux system? You can always list all the users on your Linux system but not all of them would be logged in all the time.
If you are on a multi-user Linux environment like a Linux server, checking logged in users could be useful and fun at the same time.
In this tutorial, I’ll show you various ways you list logged in users in Linux.
4 Commands to see logged users on Linux
Almost all these commands rely on the data stored in the /var or /proc directory. If you know a little about the directory structure in Linux, you know that these two directories contains data about the running processes on your system.
1. Use w command to see logged in users in Linux
Can it get any simpler than this? Just type a single letter command in the terminal and it will show the currently logged users in Linux.
And here is the output for the w command:
[email protected]:~$ w 09:54:54 up 26 min, 3 users, load average: 0.00, 0.00, 0.00 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT root pts/0 202.91.87.114 09:37 21.00s 0.00s 0.00s -bash abhi pts/1 202.91.87.114 09:47 0.00s 0.00s 0.00s w rohini pts/2 157.43.53.142 09:48 6:13 0.00s 0.00s -bash
Let me explain a few terms in the output of the w command. The same terms would be used in other commands as well.
TTY gives you information about the terminal used to log on. pts means pseudo terminal slave which indicates that the user logged in via SSH connection.
It shows the IP address of the user’s computer and login time. You can also see for how long a user has been idle (slacking at work? :D).
JCPU is the time used by all processes attached to the TTY and PCPU is the time used by the current process running by the user. You can see this current process under the WHAT column.
2. Check who is logged in with who command
Who command is another simple one. Just type who and it will show who is logged on to your Linux system currently.
You can also see the login time and the IP address of the logged on user.
[email protected]:~$ who root pts/0 Aug 6 09:37 (202.91.87.114) abhi pts/1 Aug 6 09:47 (202.91.87.114) rohini pts/2 Aug 6 09:48 (157.43.53.142)
3. Just get logged in users with users command
All the commands you saw so far give you a lot of information about the logged in users. If you are working on a script and want to know just the name of the logged in users, parsing the output of those commands would be an additional and somewhat complicated task.
This is where the users command can help you. This command only outputs the logged in users, nothing else.
4. Using finger command to see logged in users
You may need to install finger command first because not all Linux distributions have it installed by default.
It is available in the universe repository of Ubuntu and you can install it with this command:
Once installed, just type finger in terminal:
And you’ll see who is logged in on your Linux system.
[email protected]:~$ finger Login Name Tty Idle Login Time Office Office Phone abhi Abhishek pts/1 Aug 6 09:47 (202.91.87.114) rohini Rohini Rachita pts/2 13 Aug 6 09:48 (157.43.53.142) root root *pts/0 Aug 6 09:37 (202.91.87.114)
Bonus Tip: see who logged on your system since last reboot
What you saw so far was about the currently logged in users. How would you know if a user logged out?
The last command in Linux gives you information about all the users who logged in to the system since the last reboot. It will also show the log in and log out time of the logged out users.
Here’s the output of the last command which is self-explanatory I believe.
[email protected]:~$ last rohini pts/3 157.43.53.142 Tue Aug 6 10:05 - 10:05 (00:00) rohini pts/2 157.43.53.142 Tue Aug 6 09:48 still logged in abhi pts/1 202.91.87.114 Tue Aug 6 09:47 still logged in root pts/0 202.91.87.114 Tue Aug 6 09:37 still logged in reboot system boot 4.15.0-52-generi Tue Aug 6 09:28 still running wtmp begins Tue Aug 6 09:28:43 2019
I hope this quick tutorial helped you in finding the users currently logged on to your Linux system. If you know some other way to do it, please share your trick with us in the comment section.
Who Command in Linux
System administrators create multiple users to perform different tasks on a Linux computer. They may not keep track of all these users and know if a particular user is logged in or not. For this purpose, Linux provides the who command-line tool that displays a list of all the users that are currently logged on a Linux computer.
In this tutorial, we will learn what is Linux who command and how to use it with practical command examples.
Prerequisites
- Basic command-line interface understanding.
- Root or normal account access.
- Difficulty level — Easy
Who Command in Linux
The Linux who command shows a list of all the currently logged-in users on your Linux computer. This command-line utility also displays the time of the last system boot and the current runlevel of your computer. Who is an easy command to use and shows significant information about all the users who are currently accessing a Linux computer.
Syntax
The basic syntax of the who command in Linux is:
who [options] [file | argument1, argument2]
How to Use Who Command in Linux
The who command has a very simple syntax. You can use it without any options to display the list of users along with their terminal names, and login time.
For example, the following output shows only default information:
Output: root pts/0 2022-03-28 01:29 (192.168.1.10) tom pts/1 2022-03-28 02:26 (192.168.1.22) linuxopsys pts/2 2022-03-28 02:22 (192.168.1.22)
By default who shows 4 columns:
- Column 1 — The name of the user who currently logged in.
- Column 2 — The name of the terminal the user used to logged in.
- Column 3 — The date and time when the user logged in.
- Column 4 — The IP address or the hostname from where the user logged in.
The pts/0 indicates which «pseudo terminal» the user used to logged in. You may see :0 which is referred to as the actual console or display monitor.
The who command retrieves information about your system and the list of current users from the /var/run/utmp file. This is the default file to store login information in Linux.
Who Command Examples
The who command supports various options to print different information of the users in your Linux system. The following examples describe practical use cases of this command.
Display Header
By default, who does not display column headings when you list current users. Use the -H option to display header information:
Output NAME LINE TIME COMMENT root pts/0 2022-03-28 01:29 (192.168.1.10) tom pts/1 2022-03-28 02:26 (192.168.1.22) linuxopsys pts/2 2022-03-28 02:22 (192.168.1.22)
Display System Boot Time
Rebooting your computer periodically is important for its smooth functioning. You can use the -b option to check when the computer was last rebooted:
Output system boot 2022-03-23 22:49
This shows the system was last booted at 22:49 (HH:MM) on the date 2022-03-23.
Display Current Run Level
The run level is a mode of operation in Linux. You can check the run level of your Linux computer using the -r option:
Output run-level 3 2022-03-23 22:49
Display List and Number of Current Users
The number of currently logged-in users can be very high at a given time. To display a list of the users and count the number of logged-in users, use the -q option:
Output root tom linuxopsys # users=3
The output shows the names of users currently logged in the system and the total count.
Display All Information of Users Logged In
When we use the who command without any option, it does not display all the information about the users. Use the -a option to force the command to print all information:
Output system boot 2022-03-23 22:49 run-level 3 2022-03-23 22:49 LOGIN tty1 2022-03-23 22:49 645 ttyS0 2022-03-23 22:49 633 - pts/0 2022-03-28 01:29 00:33 51607 (192.168.1.10) tom + pts/1 2022-03-28 02:26 00:31 52048 (192.168.1.22) linuxopsys + pts/2 2022-03-28 02:22 . 51900 (192.168.1.22)
Display List of Dead Processes
Use the following command to display the complete list of the Linux processes that are dead:
Currently, there are no dead processes in this computer.
Who Command Options
As we described earlier, the who command without any options will display account information, such as login name, terminal name, and login time. However, you can use the command line arguments with this command to print other login information:
Option | Description |
---|---|
-a | Display all information that the who command can print |
-q | Display only the list of logged-in users and user count |
-r | Display only the current runlevel along with the last login time |
-H | Display header names for the information displayed by the who command |
-d | Display a list of all the dead processes owned by the active user |
-b | Display only the last system boot time of the operating system |
-p | List active processes on your system. You can specify the number of active processes that you want to display |
—ips | Print IP addresses instead of hostnames |
Conclusion
In this tutorial, we learned about the who command to display a list of users logged on your Linux computer. The who command works on all Linux distributions, such as Ubuntu, CentOS Stream, Red Hat, and Debian. It is part of the GNU Coreutils package.
If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks