How to List All Users in Linux

List all users in Linux

This tutorial will be helpful for beginners to List users in the Linux systems. In Linux, the user accounts will be in the /etc/passwd file.

/etc/passwd file contains the local user’s information and this file is in a human-readable format. For opening the file we can use cat / more / less / grep or egrep command

Related:  Install Git 2.30.0 in Ubuntu 20.04 / Linux Mint / CentOS

List all Users in Linux

2 ways to list the users in linux

  • cat /etc/passwd
  • getent passwd

Method 1

cat /etc/passwd

passwd file

If you are noticing the output of the file, each line contains 7 fields and it is explained below

adminpc:x:1000:1000:adminpc,,,:/home/adminpc:/bin/bash

  • adminpc – User name
  • x – represents the password is in encrypted and stored in the /etc/shadow file
  • 1000 – User ID number
  • 1000 – Group ID number
  • adminpc,,, – represents the full contact details of the user name.
  • /home/adminpc – User home directory.
  • /bin/bash – Login shell assigned for the user.

Method 2

Use the following command to list all the local users in the system

getent passwd

Search for specific users eg: root using getent

getent passwd root

Display only users names using getent , in this case we can use awk or cut command to list only user names

getent passwd | cut -d: -f1

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Secured By miniOrange