Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We all know that we have system users and service users. I am looking for a way to separate them as system users and service user list.

Is there any way ?

share|improve this question
up vote 4 down vote accepted

Based on gid, system users and service users can be separated as follows,

/etc/passwd contains list for all users along with some other information. Service users or real users have gid greater than or equals to 1000. So a list of real users can be obtained as,

awk -F: '($3>=1000)&&($1!="nobody"){print $1}' /etc/passwd

Also a list of system users (gid < 1000) can be extracted as,

awk -F: '($3<1000){print $1}' /etc/passwd

How it works

The contents of /etc/passwd are like,


When using awk with -F: it splits the contents of a line into several fields treating : as field separator. First field contains the user name and third field has the gid.

Hence to extract real users awk just check value of third field is greater than equals to 1000 and it is not nobody user and prints the first field i.e., the user name.

To list all system users it just checks gid is less than 1000 and prints the user name.


As you want to list root(gid = 0) in real user list. Get real users as,

awk -F: '($3==0)||($3>=1000)&&($1!="nobody"){print $1}' /etc/passwd

Get system users as,

awk -F: '($3<1000)&&($1!="root"){print $1}' /etc/passwd

Note I am always ignoring nobody user.

share|improve this answer
Thank you for answering – Raja Feb 15 '14 at 6:55
How it can take care of root user ? – Raja Feb 18 '14 at 18:16
did not understand your point? you will get root as system user. do you wish to include root in real user list? – souravc Feb 18 '14 at 18:27
yes because he is also user. – Raja Feb 19 '14 at 3:43
@rajagenupula is it ok now? – souravc Feb 20 '14 at 16:20

To list local (system users) than can login and have homedir and GID less than 1000

 cat /etc/passwd | cut -d: -f 1,3,6 | grep "[1-9][0-9][0-9][0-9]" | grep "/home" | cut -d: -f1

To list all other users:(mainly system users and have GID less than 1000):

cat /etc/passwd | cut -d: -f 1,3,6 | grep -v "[1-9][0-9][0-9][0-9]"  | cut -d: -f1
share|improve this answer
Root user's group ID and user's ID is less than 1000 right.thank you for answer – Raja Feb 13 '14 at 18:29
@rajagenupula yes for sure. only root is the exception. and in ubuntu generally, root cannot login by default. – kamil Feb 13 '14 at 18:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.