A VPS server is suitable for team-based projects and is commonly used among tech research groups and development communities. This also means that VPS is usually used by multiple users at once and for that reason, it is important to secure your personal data in a VPS. We can list the users on a VPS and see the permissions and activities of the users to aid us in protecting our data. In this article, we will guide you on how to list users in a Linux based VPS. The Linux distribution used in this guide is the Ubuntu OS.
View All Users
For Linux operating system, there is a file called passwd, which stores all information regarding the user registrations. This file is located at “/etc/passwd”, and to access, the file’s content, first, open the terminal. It can be done by searching for the terminal application or right-click on the desktop and selecting the “Open Terminal” option. Type in the following command in the terminal to access the content of the file.
The output will be a list of users’ information such as the following output.
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh ...
The fields of data are separated by colons, where the format goes by the following way.
“user_login_name” is the user’s login name, “password” is the password of that specified user, do note that the password is just a placeholder while the actual password is located in a different file. “userID” is the user’s unique identifier which will be different for everyone, same goes to the “groupID”.
“comment_field” refers to the short description of the user, “home_directory” refers to the main directory of the users and “user_shell” is the shell used for signing into the system. However, if you just want to view only the name of users, you may run this command.
cut -d : -f /etc/passwd
It is possible to create groups in Linux too, where you can gather a number of users and grant them certain privileges in the system. The group information is stored in a different file called group, which can be found at “/etc/group”. Similarly to view users, first you have to open the terminal, then access the content using the following command line.
The output for each line should be something similar to this.
Also, similarly to the users, you can choose to only view the group name using the following command.
cut -d : -f 1 /etc/group
View Active Users
To list all logged-in users, just open the terminal and run “w”.
You will be able to see how many users are online and several fields. To list down all the fields.
- User – refers to the username.
- TTY – refers to the terminal name.
- From – refers to the name of the remote host.
- Login@ – refers to the login time.
- Idle – refers to the duration of idle time.
- JCPI – refers to the time used by processes attached to the terminal name.
- PCPU – refers to the time processed displayed in the WHAT field.
- WHAT – refers to the user’s current process.
There is another command that works the same way as “w”, which is the “who” command, however, it will show a less detailed version of it.