It is essential to learn these commands to be able to quickly see a list of users in your Ubuntu VPS system. This article shows you how to use the command-line to list users in Ubuntu Linux VPS.
How to List Users in Ubuntu Linux VPS: A Beginner’s Guide
If you want to view all users in Linux Ubuntu VPS, you can use the /etc/passwd command, as local user details are saved in the “/etc/passwd” file. There are two ways to execute this command, as follows:
Or
After executing the above command successfully, you will obtain an output that looks like this:
These output lines relate to the users. The number of lines depends on the number of users in the system.
Each line contains seven different fields that represent the details of a specific user. For example, the first line of the output is root:x:0:0:root:/root:/bin/bash, which represents:
- root – the user’s login name.
- b – the password’s placeholder, as the actual password saves into a separate file.
- 0 – the UserID of the user.
- 0 – the GroupID of the user.
- root – a command field with some details about the user.
- /root – a Home directory that is the main directory of the user.
- /bin/bash – a User shell.
Note that colons (:) are used for separating the values in the output.
Execute the following commands to see the names of the users:
Or
How to View Groups in Ubuntu Linux VPS
You can also create groups by gathering several users and giving them some administrative permissions for the system. This option is beneficial for creating groups of users within the same system. The information about these groups will be saved in the Group folder. So, use the following command to view groups in the terminal.
After executing the command successfully, you obtain an output like this:
Use the below command if you want to display the names of the groups:
How to List Users in Ubuntu Linux VPS Using the getent Command
The getent command is used for displaying entries from the database configured in the /etc/nsswitch.conf file. It covers the passwd database that can be used for querying the list of users. The getent command displays entries from databases configured in the /etc/nsswitch.conf file, including the passwd database, to query a list of all users.
Use the following command to execute getent in the terminal:
After executing the command, you will receive an output like this:
You can use awk or cut for printing the first field that contains the username:
getent passwd | cut -d: -f1
How to View Logged in Users with w Command
You can use the w command to list logged-in Linux Ubuntu VPS users. To use this command, type “w” in the terminal and execute it by hitting Enter.
After executing the command, you will receive an output that consists of various user information, such as login time, idle time, and remote host information. The details in the output are as follows:
- user - represents the username.
- TTY - represents the terminal name.
- From - represents the remote host’s name.
- Login@ – represents the login time.
- Idle – represents idle time.
- JCPU – represents the time used by the process related to the TTY.
- PCPU - represents the time used by the specific process displayed in the WHAT field.
- WHAT - represents the current process of a user.
Conclusion
This article covered in detail how to list users and user information in Ubuntu Linux VPS. These commands help system administrators to obtain user details that use a specific system and find out other important details about them. We hope the article was informative and comprehensive enough for your needs.
from Linux Hint https://ift.tt/2KFA0Lm
0 Comments