How To List All The Users In A Linux Or Unix System?
 

How To List All The Users In A Linux Or Unix System?

 

This post was last updated on August 1st, 2020 at 03:21 pm

Linux is a multi-user operating system. It means more than one user can use system resources simultaneously. To use the system resources a user must have a user account on the system. So before we start discussing today’s topic you should understand the type of accounts that a Linux/Unix system can have.

Types Of User Account

Basically there are three types of the user account in Linux or Unix –

Root account –

A root account is the most privileged account in Linux/Unix. You can compare this account with the administrator account on Windows. It can perform tasks such as installing/removing a package, alter the configurations, managing other users of the system, etc. Root always has a User id (UID) of 0. A root account is created automatically at the time of operating system installation.

Normal user account –

A normal user account is created by a user while installing OS or after the installation of OS by providing the required information. Usually, these accounts have limited access to system resources. To create this type of user account you can read how to add/remove users in Linux.

Service or system account –

A service account is used for running applications and processes. And these are also created to own data and configuration files. A service or system account is not intended to use by people except for performing administrative tasks. The UID in the range of 0 to 1000 is for service accounts and is configurable in /etc/login.defs. You can create a service or system account using -r flag with useraddcommand. Look at the command below –

useradd -r system_account_name

The /etc/passwd file

This file contains the information of all the user accounts in a system. Each line contains a single user with some other information. You can easily display this file using cat or less command in the terminal. Use one of the following commands-

cat /etc/passwd

Or

less /etc/passwd

Or

more /etc/passwd

Now you will see that each line has seven fields. And each of them is separated by a colon. The first field in each line is the user names of either root, normal user, or service/system account. Each field of a line contains the following information.

  • Username
  • Encrypted password(x means the password is stored in /etc/shadow file )
  • User ID (UID)
  • User’s group ID
  • Full name of the user
  • User’s home directory
  • Default login shell

How to display the list of user names only

To display the list of user accounts use the following command in your terminal. This list will include all types of account i.e. root, normal user, and system/service accounts. Use the following command –

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

And after the execution of this command, you will get the output something like this –

Using getent command to display the list of users

getent is a Unix command that helps a user to get entries from a number of important text files known as databases. We can use this command to display the content of /etc/passwd file.

getent passwd

Or use the following command if you want to display the field containing username only –

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

Or

getent passwd | cut -d: -f1

How to search for a specific user

If you want to search for a specific user, you can do this by using grep with getent command. Use the following command in your terminal –

getent passwd | grep lalit

To count the total number of users, use the following command –

getent passwd  |  wc -l

Now I hope this article is useful to you. If you want to say something on this topic write us in the comments below.

Previous How To Find IP Address From Domain Name In Linux/Unix?
Next Understanding Users And Groups In Linux/Unix
 

About author

You might also like

Linux Terminal 0 Comments

How To Change User’s Password Through Terminal In Linux/Unix?

This post was last updated on August 1st, 2020 at 12:14 pmLinux or Unix is the multi-user operating system that means more than one user can use system resources simultaneously.

Linux Topics 0 Comments

Understanding The Output Of Top Command In Linux Or Unix

This post was last updated on August 1st, 2020 at 08:48 pmThe top is one of the most frequently used command in Unix like operating systems for the administrative tasks.

How To 0 Comments

How To List The All Enabled Repositories In Linux?

This post was last updated on August 1st, 2020 at 01:28 pmA software repository is a database of software packages stored on a remote server. Generally, these packages are retrieved

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply