Linux operating system has made everything very simple. It doesn’t stick the user with one approach as a single function can be performed in multiple ways. Whether you want to go with the built-in commands or prefer to install any tool, the choice is yours!
Similarly, in this guide, we will see many ways to find the user id through different commands. But the question is, why would you need to get an identity as in most of the cases, the admin is the only user.
It is necessary to find your ID when you give access to other people. In this case, a single pc has multiple accounts from which the users logged in. Another case might occur if the user is connected remotely on a server and needs a quick response to get details of the logged-in username.
How to Find User ID in Linux
In Linux distributions, we have multiple commands that help to find the user ID very quickly:
The id command is the simplest way to display a list of real and effective users, and it also shows the group IDs.
You can either simply type the “id” in the terminal or use the username with the “id” command as mentioned below:
The “getent” command in UNIX and Linux-like systems is used to fetch the entries from a system database supported by NSS (Name Service Switch) libraries. The user details have been stored in the passwd and group databases.
To get the user’s details through the getent command, follow the syntax:
So, if I want to show the details of user ID, the command would be:
The “lslogins” command utility in Linux must grab all the available details from the system files about specific users only.
The “-u” flag in the “lslogins” command is used to show user accounts:
The “w” command helps to display the current logged in users and the actions they performed in a system:
The “who” command utility is used to print the username currently logged in and the terminal details with date and time. You can either simply type the “who” or use it with the flag “-u” in the terminal:
To display the only username of the current logged in account, type:
The “grep” command is considered a powerful Linux tool to search for a particular pattern. It helps to search data (text or strings) from the given and display it. To display the user details from the/etc/passwd file, follow the command:
users and echo $USER Command
The “users” command is used to display a list of all users logged in to the system, whereas the “echo $USER” is an alternate of the command “whoami.” It displays a one-line answer.
$ echo $USERS
Using the last command, the user can print the list of the last logged in users to the operating system:
If you want to install the command-line tool to search for the user’s information, nothing is best from the “finger” command.
The “finger” command-line utility in Linux is used to print user information in the terminal. It is not a built-in tool in most Linux distributions. So, to get it, install it first:
Now, to show the necessary information about the user that includes the user’s real name, directory information, shell, etc., type:
In this write-up, we have learned several ways to find the user identity on the Linux system. The Linux system introduced many command-line utilities to display the user ID. Also, if you want to install the tool to get information, we have mentioned the “finger” command-line tool to print all necessary details of the user.