Debian

How to List Users in Debian 12

How to List Users in Debian 12

User management is one of the important duties of the system administrator that helps you keep the system secure and organized. Debian is a multiple-user operating system and each user has its own set of permissions and privileges. To ensure the system’s privacy and prevent unauthorized access, the administrator must know the information of every user and manage them wisely.

This guide aims to learn two approaches for listing the users in the Debian 12 that will help you manage multiple users on your system easily.

Quick Outline

 

How to List All Users in Debian 12

The are two ways to list users in Debian 12:

 

How to List Users in Debian 12 Through Terminal

Below we have listed the various commands to list users in Debian 12:

 

How to List Users Using cat Command in Debian 12

The cat command in Debian is widely used to display the content of files quickly. You can preview the information of users in Debian by viewing these two files:

 

1: Use cat Command to View List of Users in the ‘/etc/passwd’ File in Debian 12

The information of each local user account is stored in the /etc/passwd file in Debian 12. You can display this information inside this file using the cat command:

cat /etc/passwd

The above command will display the information of each user; the information consists of multiple fields separated by the colon as shown below:

User Name : Password : <strong>UID </strong>(User Identification) <strong>: GID </strong>(User Group ID) <strong>: Full</strong> <strong>Name :</strong> <strong>Home Directory : Shell Used

Here:

1: The User Name is the login name of the user.

2: The next field is the encrypted password and x represents that the password is stored in the /etc/shadow file.

3: Next to the password is UID, GID, the Full Name of the user, and its home directory.

4: The last field represents the login shell and that is the default /bin/bash.

You can also use less or more commands to customize the output. These commands are used to view the content of large files interactively as you can easily browse through them.

The less command shows the file in separate sections or pages and provides the navigation.

less /etc/passwd

The more command will display one page of the file at a time:

more /etc/passwd

You can use various flags with the cat command to customize the output, such as:

 

1: Get Only Usernames in Debian 12

Execute the following cat command to view only the list of usernames in Debian 12:

cat /etc/passwd | cut -d: -f1

Moreover, you can also use the cut command to display the only names of the users:

cut -d: -f1 /etc/passwd

 

2: Get the Total Number of Users in Debian 12

To get only the total number of users on Debian, run the following cat command:

cat /etc/passwd | wc -l

 

2: Use cat Command to View List of Users in /etc/shadow File in Debian 12

The /etc/shadow file stores the password hashes and other password related information of the user accounts. You can use the cat command followed by the shadow file location to retrieve the list of users in Debian 12:

sudo cat /etc/shadow

 

2: How to List Users Using awk Command in Debian 12

The other command used to display only the name of the users is the awk command. The awk is the command line utility that interprets the information from the /etc/passwd file similar to the cat command.

When you execute this command, the list of all the users will appear on your screen:

awk -F':' '{ print $1}' /etc/passwd

 

3: How to List Users Using getnet Command in Debian 12

In Linux, getnet is a common way to get the user information. It includes the passwd and group databases that store the information and displays the database configured in /etc/nsswitch.conf file. You can use the getnet command in Debian 12 to:

 

1: Get the Details of All Users

To get the detailed information of all users using getnet in Debian 12, execute the following command:

getent passwd

 

2: Display Only Name of Users

You can limit the output by executing the below-given command to get only the names of users on Debian:

getent passwd | awk -F: '{ print $1}'

 

3: Check the Existence of Specific User

You can use the getnet command to view the information of specific users in Debian, it can be done using:

getent passwd <name>

Here, in place of <name> specify your username.

You can also use the grep command with getnet to display the user information in Debian:

getent passwd | grep <name>

 

4: Display Regular Users

In Linux, there are two types of users: system users and regular users. The system user is created while installing the OS and the regular user is created by the user who has sudo privileges. The regular user has a home directory. You can use UIDs to search users in the specific range using the following syntax:

getent passwd {[first-UID]..[last-UID]}

To get the minimum and maximum value of the user ID execute the following command:

grep -E '^UID_MIN|^UID_MAX' /etc/login.defs

To display only the regular users in Debian 12, execute the following command:

getent passwd {1000..60000}

The range in the above command is the range of user IDs of regular users in Debian. To print only usernames you can also execute the below command:

eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1

4: How to List Users Using compgen Command in Debian 12

The compgen is the bash built-in command of Linux that can be used with different options to get information. When you use this command with the -u flag, it displays the list of all users in Debian:

compgen -u

How to List Users in Debian 12 Through GUI

Another approach for listing regular users in Debian is through the system settings and to do so follow these steps:

Step 1: Navigate to Activities and search for Settings to open the System Settings:

Step 2: Next, click on Users from the left panel:

Step 3: Click on the Unlock button that appears at the top of the screen to unlock the user settings:

Step 4: A prompt will appear on the screen, asking you to enter the password of the Administrator account; type the password and click on Authenticate button to continue:

Step 5: Scroll down and you will find the list of users under Other Users; here you can add another user, modify the information of existing users, and also remove the user from the system:

 

How to View Current Login Users in Debian 12

To get the list of all the connected users in Debian 12, you can execute the following command:

who

The below command also displays the names of the current users:

users

 

Conclusion

The system administrator has to ensure the security of the system by keeping a check on all users. Using the above-mentioned two methods such as through terminal and GUI, it becomes easier to manage the system and get the user information. Through the terminal, you can use the cat, getnet, awk, and compgen commands to view the list of all users. You can also use the who and users commands to view the currently logged-in users on your system. We have discussed these commands in this post and also discussed how this command works with different arguments.

Similar Posts