How to see Logged in Users in Linux [4 Simple Ways] (2024)

How to see Logged in Users in Linux [4 Simple Ways] (1)

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

How to see Logged in Users in Linux [4 Simple Ways] (2)

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.

w

And here is the output for the w command:

abhi@test-server:~$ w 09:54:54 up 26 min, 3 users, load average: 0.00, 0.00, 0.00USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot pts/0 202.91.87.114 09:37 21.00s 0.00s 0.00s -bashabhi pts/1 202.91.87.114 09:47 0.00s 0.00s 0.00s wrohini 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.

who

You can also see the login time and the IP address of the logged on user.

abhi@test-server:~$ whoroot 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.

abhi@test-server:~$ usersabhi rohini root

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:

sudo apt install finger

Once installed, just type finger in terminal:

finger

And you’ll see who is logged in on your Linux system.

abhi@test-server:~$ fingerLogin Name Tty Idle Login Time Office Office Phoneabhi 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.

last

Here’s the output of the last command which is self-explanatory I believe.

abhi@test-server:~$ lastrohini 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 inabhi pts/1 202.91.87.114 Tue Aug 6 09:47 still logged inroot pts/0 202.91.87.114 Tue Aug 6 09:37 still logged inreboot system boot 4.15.0-52-generi Tue Aug 6 09:28 still runningwtmp 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.

How to see Logged in Users in Linux [4 Simple Ways] (2024)

References

Top Articles
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 6210

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.