Let's say I want to keep the /etc/passwd file divided into system users like admin, wheel, root etc., and by actual users all at the end.

How do I do that? By creating subdirectories?

  • 1
    Do you mean /etc/passwd? What's wrong with using the standard tools? What sort of "managing" of this file would you want to do? Please edit your question to clarifiy what you are actually trying to achieve. Commented Mar 23, 2018 at 23:33
  • hi roaima.... what i was trying to ask is how to keep the /etc/passwd file divided into system users like admin, wheel, root etc and by actual users all at the end. thank you - denny
    – Denny
    Commented Mar 23, 2018 at 23:51
  • you can always (carefully) edit the file manually and move lines around. new users are appended to the bottom. how often are you adding system users and regular users? If nothing else, you can sort -n -t ':' -k3 /etc/passwd | less
    – ivanivan
    Commented Mar 24, 2018 at 0:19

2 Answers 2


You can edit the file (carefully!) with vipw. (Don't use an editor directly on the file as vipw will sanity-check the result before updating /etc/passwd.) If you want a different editor, such as nano, you can request that like this:

vipw                # Uses default editor
EDITOR=nano vipw    # Uses nano as the preferred editor

You can sort the file by ascending order of UID. This will separate system accounts that typically have lower numbers from user accounts that typically have higher numbers:

sort -n -t: -k3,4 /etc/passwd >/etc/passwd.old &&
    cp -fp /etc/passwd.old /etc/passwd

(That can be run all on one line if you prefer.) An unchanged copy of the password file is left in /etc/passwd.old.


UID ranges define system vs. user accounts.

That is unless you are using a global LDAP server or equivalent to manage users & groups which would still conform to the reference but merely extends the ranges.

Typically system accounts or those with a UID less than 100 are system reserved. Applications that create a local entry to assist with privilege escalation problems in the event of a design flaw are 100 - 499. 500 and above are for users.

Typically manual editing of the local passwd database is frowned upon and should be managed with tools such as useradd, userdel, passwd, usermod etc.

If you are simply looking for a way to audit accounts and want them sorted on output the following bit will work.

sort -d: -k2 /etc/passwd

  • For persistent sorting, there is pwck -s and grpck -s.
    – telcoM
    Commented Mar 26, 2018 at 21:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .