How to List Current Logged-In Users on Linux


Linux being a multi-user system allows multiple users to log in and run various programs at the same time. As a normal Linux user or system admin, you may sometimes need to check which users are currently logged into your system.

This information can be useful for various reasons such as for troubleshooting performance issues, monitoring user activity, or for simply checking who else is using the system.

There are several methods to list current logged-in users on Linux and see what they are doing.

1. The users Command

The users command in Linux lists all users who are currently logged in in alphabetic order.

Note that if a user has two login sessions, it will appear twice in the output.

The output below tells that there are three users logged into the system currently.

users command

2. Using the who Command

The who command prints the list of users currently logged into the system along with other information such as the terminal they’re using, login date and time, and IP address or hostname of the system if a user is on a remote machine.

To list current logged-in users on Linux, use the who command as follows:

who command

You can also use the who command with -a and -H flags to display idle time and PID of the user’s login shell:

 who -a -H 
who command output

3. Using the w Command

The w command in Linux shows logged-in users and their activities. It prints the list of users and their current processes in the command line.

The header in the output summarizes the status of the system which includes the current time, system uptime, number of logged-in users, and load average. Then for each logged-in user, it displays the user name, tty name, time of login, idle time, time used by all the processes (JCPU), time used by the current process (PCPU), and the current process the user is running.

w command

4. Using the last Command

The last command lists current as well as past logged-in and logged-out users. The information it provides includes the name of users and terminals, the IP address of the system they are logged in from, and the date and time of login.

To find the list of users logged in currently, use the last command with the -p now option as follows:

 last -p now 
last command

5. The finger Command

The finger command shows information about all the logged-in users on Linux including their username, tty, login date and time, and IP address. You can easily install finger on your Linux distribution using the default package managers.

On Debian-based distributions:

 sudo apt-get install finger 

On RHEL-based distributions:

 sudo yum install finger 

To display information on current logged-in users, run the finger command without any command-line options:

finger command

If you run the command with the username, it displays more information about the particular user:

finger command user

6. Using the top Command

The top command displays a summary of system information such as uptime, number of logged-in users, load average, number of tasks running, etc. It also shows the processes that are currently running on the system and their resource usage.

Once you know who is currently logged in to your system, you can use the top command to find the current processes for the user:

 top -u username 
top command

Keep an Eye on User Activity on Linux

With these commands, you should now be able to easily list logged-in users on a Linux system. Whether you are a system administrator monitoring user activity and performance or simply a curious Linux enthusiast, these commands will help you find who else is logged in and what they’re doing.

Among these commands, you can also use the who and w commands to track your Linux system’s shutdown and restart history.


Source link

Leave a Reply

%d bloggers like this: