How to List all Users in Ubuntu?

LIST ALL USERS

There can be multiple users on a Linux system. If you want to list all users in Ubuntu, the information is present in the /etc/passwd file. This file stores the list of users on the system along with important information regarding these users. /etc/passwd file is used at the time of login.

We can obtain the list of users by displaying the content of /etc/passwd file.

Display contents of /etc/passwd file

To display content of /etc/passwd file simply use the cat command.

$ cat /etc/passwd
Etcpasswd File
output of the /etc/passwd file

Each line in the output corresponds to a user. There is some important information available for each user. The seven fields are:

  • Login name
  • Encrypted Password
  • UID number
  • GID number
  • GECOS
  • Home directory
  • Login shell

First field is the name of the user.

Using awk command to list all users in Ubuntu

By using awk command we can get just the first field from the /etc/passwd file. Awk is a powerful text manipulation tool in Linux.

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

This command displays the name of all users on the system.

Creating a new user

Apart from knowing how to list all users in Ubuntu, it is important also to know how to add a new user. To create a new user in Linux, use the following command:

 $ useradd username

This will create a new entry in the /etc/passwd file.

Get information about a particular user

You can use grep command to get information about a particular user from the /etc/passwd file. This is useful if there are a lot of users in the /etc/passwd file. This can help in checking for the existence of a particular user.

$ grep username /etc/passwd
Grep Username

We get information about a user named Adam from the /etc/passwd file.

Conclusion

In this tutorial we saw how we can list all the users in a Linux System. You can learn more about the /etc/passwd on the website linked here. Feel free to visit our homepage and read through other articles if you’re interested in learning more about Linux.