Linux List Users From /etc/passwd File

Each line in the /etc/passwd represents user login information. Let us "less /etc/passwd" file.

less /etc/passwd

Format of /etc/passwd is shown below...

  1. User name.
  2. Encrypted password (x means that the password is stored in the /etc/shadow file).
  3. User ID number (UID).
  4. User’s group ID number (GID).
  5. Full name of the user (GECOS).
  6. User home directory.
  7. Login shell (defaults to /bin/bash).

If you want to "list username" only, Pipe it to awk ...

cat /etc/passwd | awk 'FS=":" {print $1}'

Linux List All Users Using getent Command

The getent command shows information from the /etc/nsswitch.conf and /etc/passwd (LDAP) files.

getent passwd

To paginate, pipe it to less.

getent passwd | less -S

Linux Check Whether User Exists

To check if user exists, just pipe the output of getent passwd to egrep as shown below.

sudo getent passwd | egrep <username>

Linux Find UID Min and Max values

Uids are stored in the /etc/login.defs. Whenever a new user is added using "adduser" command, uid is created automatically.

To check the UID min and max values on your system, you can use the following command...

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

Output of above command...

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