How to List All Logged-In Users in Your Linux System

Linux TLDR
Last Updated:
Reading time: 3 minutes

Have you ever been curious to know who is connected to the remote machine or server you have been working on? I mean, who doesn’t want to do that?

Look, listing all the user accounts in your Linux system is quite an easy task, but that doesnโ€™t mean that all those users are connected to the target machine.

However, you can read this article to learn four simple ways to list all the logged-in users on the target machine. Once you find them, you can kick them out of the target machine or say “hi” to them using the write command.

Tutorial Details

DescriptionList All the logged-In Users in Linux
Difficulty LevelLow
Root or Sudo PrivilegesNo
Host System and ArchitectureUbuntu 22.10 (x64)
OS Compatibility Ubuntu, Manjaro, Fedora, etc.
Prerequisitesw, who, users, finger
Internet RequiredNo

4 Ways to Check Logged-in Users in Linux

To achieve this task, there are various built-in and external command-line tools, but most of the commands share the same output, so once you understand one, you can understand them all.

In addition to that, all the information related to the logged-in users and their activity is pulled from the “/var/run/utmp” file and “/proc” directory.

Using the w command

The w command is a simple single-character command-line utility that can tell you all of the logged-in users on the target machine, as well as their activity.

$ w

Output:

w command output

From the above output, itโ€™s clear that in total, three users (“linuxtldr“, “david“, and “jake“) are connected to the target machine.

The output from the preceding command will be identical to the rest of the upcoming commands, so letโ€™s get a good grasp on each field in the output.

  • USER: The user who is currently logged-in.
  • TTY: How user are connected to the target machine: “tty*” means the user is physically connected to the target machine from the command-line, and “pts” means the user is connected remotely via SSH.
  • FROM: The user’s hostname or IP address.
  • LOGIN@: The time when the user logged-in, in 24-hour format.
  • IDLE: The amount of time the user has been idle.
  • WHAT: The userโ€™s current process with options and arguments.

Once you understand this field, the next three commands become self explanatory. So, letโ€™s move on to the next command.

Using the who command

The who command is another tool to find all the users logged-in to the target machine.

$ who

Output:

who command output

As you can see, the output is self explanatory.

Using the users command

The previous two commands provide far more information than is necessary while writing a shell script, as you might only be interested in knowing the names of the logged-in users.

The users command is a perfect fit for this type of situation, where the names of the logged-in users matter above all.

$ users

Output:

Users command output

Using the finger command

The finger command is an external utility that can give you a list of all connected users to the target machine. Although, this tool is not shipped out of the box, it is available in major Linux repositories.

Execute any one of the following commands to install it on your system.

$ sudo apt install finger                              #On Debian and Ubuntu
$ sudo dnf install finger                              #On Red Hat and Fedora

After the installation is complete, run the following command without any options to get a list of all logged-in users on the target machine.

$ finger

Output:

finger command output

How to Find Past Logged-In Users Information

All of the above mentioned methods will only give you the list of users while they are connected to the target machine; once they quit, their entries will be removed from the output.

However, you can use the last command to list all the previous users who are no longer logged-in in order to determine when they logged in and out.

$ last

Output:

last command output

Here comes the end of this article.

All the tools mentioned in the article are great, but if you know any tool that is missing and should be included, let us know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.