Linux Command To Show / List All Users In the System

October 18, 2012 | By
| Reply More

In Linux, you will be able to find two types of users; which are normal users (created using useradd command) and system users. Most of the system users are created while installing the OS which creates the users during various package installations. System users should be having low UID values (usually 0-99) as defined in /etc/login.defs. The users that you create using useradd which take some higher UIDs than the minimum values defined in /etc/login.defs file.

UID_MIN 500
UID_MAX 60000

The above values in /etc/login.def file define that the normal users should have UIDs in the range 500-60000.

When you create a username using “useradd”, a corresponding entry will be created in the file /etc/passwd. This file will contain information about all users.

A snippet of /etc/passwd file is as follows.

root:!:0:0::/:/usr/bin/ksh
daemon:!:1:1::/etc:
bin:!:2:2::/bin:
sys:!:3:3::/usr/sys:
adm:!:4:4::/var/adm:
uucp:!:5:5::/usr/lib/uucp:
guest:!:100:100::/home/guest:
nuucp:*:6:5:uucp login user:/var/spool/uucppublic:/usr/sbin/uucp/uucico
paul:!:2010:1::/home/paul:/usr/bin/ksh

So, you can use this file to find the list of all users in your Linux machine.

1. Listing all users in your machine

You can use the following command to list all users in your machine.

# awk –F’:’ ‘{print $1}’ /etc/passwd

This will list all system users and normal users.

2. Listing all System Users in your Linux machine

System users will use UIDs less than 500 as per the settings of our /etc/login.defs file. So, you can use the below command to list all system users.

# awk –F’:’ ‘$3<=500 {print $1 “ “ $3}’ /etc/passwd

3. Listing all normal users created using useradd command

As per the settings in login.defs file, the normal users should have UID in between 500 and 60000 in our Linux machine. So, you can use the following command to list the normal users.

# awk –F’:’ ‘$3>=500 && $3<=60000 {print $1 “ “ $3}’ /etc/passwd

Filed Under : LINUX COMMANDS, LINUX HOWTO, USER MANAGEMENT

Tagged With :

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.