In Linux/Unix Machine we have various users which could login on machine to use its resource or even some users unable to login but has some applications access to run to make service available on machines.In this post we will how Linux list all users in the system

Some previous post on managing Linux users and Group.

1 Managing Users and Group part1 and part2
2. Linux Users & Groups

These are various ways to categories users according to their user, shells or home directory. We can list our systems, central authorised like LDAP, NIS users with various ways. In this post we will see some of these ways through which we could list our users.

In Linux/Unix machines, we have one file called /etc/passwd which contain all users list. This file format is described in another post. Let’s see another look on this file and understand some new facts about it.

root:x:0:0:root:/root:/usr/bin/zsh
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
...
...
...

This file contain user’s name and same other important facts for users which always used while user login on systems, but this file only contain systems local users. It’s possible to login through centralize mechanism like LDAP or NIS, which is widely used. But those users are not shown in this file, to see them we can use other commands like

getend password

or 

getent group

In these outputs, we have first field User name, we can filter like below

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

or 

cut -f 1 -d: /etc/passwd

In case we need to see specific users detail in /etc/passwd file, we could use use grep command for same to filter from /etc/passwd file.

▶ grep root /etc/passwd   
root:x:0:0:root:/root:/usr/bin/zsh

In Linux, we have one file which used to maintain some important parameters which has continuously used while creating any new local user in machine, like password expiration, login shell, home directory creation etc. In same way we have min_uid value which used to manage automatic value of next User ID, if we explicitly not used any uid while creating it