+4 votes
39 views
List Ubuntu Users

in Linux/Unix by (551k points)
reopened | 39 views

1 Answer

+5 votes
Best answer

1 List Ubuntu users using /etc/passwd file
2 List Ubuntu users by checking availability
3 List Ubuntu users using Getent
4 List Ubuntu users by checking the types

To stay up to date, remember to subscribe to our YouTube channel!
SUBSCRIBE ON YOUTUBE

 

One of the components that are fundamental in Linux, in this case we are talking about Ubuntu, are the users, we know that a user is required to log in to Ubuntu but what we do not know is that there are various types of users such as:

 

Types of users
  • Administrator user: these are the root users who have the capacity and permissions to manage all the system parameters, for which their use is of special care since some error can completely affect the system, for the root user the UID is zero (0).
  • Special users or system users: this is a type of user that, although it does not have root privileges in some cases, can assume it for specific tasks, some types of these users are bin, daemon, adm, lp, sync, shutdown. For this case the UID is between 1 and 100 (this is set in the /etc/login.defs file).
  • Normal users: these are the users that we create which have a working directory located in the /home directory, this user has full privileges in the working directory, in Ubuntu the UID of this user will be in values ​​greater than 500.

 

 

 

For various reasons it is possible that we need to have access to the users who are hosted in the system for administrative reasons, either to edit their permissions, delete a user or validate logins, TechnoWikis will explain various ways to achieve this information and list Linux users completely..

 


1 List Ubuntu users using /etc/passwd file


The /etc/passwd file is the file where all the user accounts in Ubuntu are hosted with their respective details.

 

Step 1

To access this information we are going to open the terminal and execute the following command:
 less /etc/passwd 
image

 

Step 2

The less command allows us to have access to the information of a particular file and for this case it will be /etc/passwd, the result that we will see is the following:

 

image

 

Archive
This file is made up of the following:

 

  • username: refers to the name of the user.
  • password: in current Linux distributions, this field will contain an "x" indicating that the password is stored in the "/etc/shadow" file or in some secure authentication system.
  • UID: this is the User ID (user ID) which is a unique number that is assigned to the user, remember that each user will have a different UID.
  • GID: indicates the Group ID (group ID) which is the identifier of the group where the user is added.
  • User info: additional information about the user is shown there, details such as the full name or description are part of it.
  • home directory: indicates the user's home directory, there we will see the user's personal files.
  • login shell: is the default shell used when the user logs into Ubuntu.

 

 

Step 3

To see these results we can also use cat as follows:
 cat /etc/passwd 
image

 

Step 4

If you do not want to have access to all the details, but only to the username, you can use one of the following commands:
 awk -F: '{ print $1}' /etc/passwd cut -d: -f1 /etc/passwd 
image

 


2 List Ubuntu users by checking availability

 

Step 1

It is possible that for various reasons we need to validate if a user exists in the system, it is possible to search for a user directly with the following command:
 get passwd | grep "user" 
image

 

Step 2

We can see the users that meet the criteria of this name and their respective details, if we want to see the login details we will execute the following:
 getent passwd “user” 
image

 

Step 3

If you want to know the number of existing user accounts in Ubuntu, we will execute the following command:
 get passwd | toilet -l 
image

 


3 List Ubuntu users using Getent


In Ubuntu the getent command is used to retrieve information from system databases such as /etc/passwd, /etc/group, /etc/hosts and more in order to perform queries related to users, groups, hosts and some more parameters.

 

Step 1

In the terminal we will execute the following. We can see the details of the user as we have mentioned above.
 get password 
image

 

Step 2

It is now possible to filter these results to only see the username with one of the following commands:
 get passwd | awk -F: '{ print $1}' getent passwd | cut -d: -f1 
image

 

Step 3

We can see all the users by scrolling down a bit in the terminal:

 

image

 


4 List Ubuntu users by checking the types


We mentioned at the beginning that there are system users and normal users, so it is essential to know the name that is in each segment, remember that the system assigns a UID to the user for identification and this UID is taken from the /etc/login.defs file. .

 

Step 1

There it will be possible to validate the UID_MIN and UID_MAX values ​​using the following command:
 grep -E '^UID_MIN|^UID_MAX' /etc/login.defs 
image

 

Step 2

This result tells us that normal users are managed in a range of UIDs between 1000 and 60000, to list these users we execute:
 get passwd {1000..60000} 
image

 

Step 3

Because the UID_MIN and UID_MIN values ​​are system variables, we have the opportunity to view the results globally with the command:
 eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} 
image

 

Step 4

In order to see only the usernames we are going to execute:
 eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1 
image

 

These are the options that we teach you to see the users in Ubuntu and thus manage them in a complete way.

 


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Feb 17, 2020 in Linux / Unix by backtothefuture (551k points) | 279 views
+5 votes
1 answer
asked Jun 22, 2023 in Linux/Unix by backtothefuture (551k points) | 42 views
+4 votes
1 answer
asked Nov 11, 2022 in Linux/Unix by backtothefuture (551k points) | 38 views
+3 votes
1 answer
asked May 17, 2023 in Linux/Unix by backtothefuture (551k points) | 42 views
+3 votes
1 answer
asked Nov 2, 2019 in Linux / Unix by backtothefuture (551k points) | 248 views
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users