Let's say I want to keep the
/etc/passwd file divided into system users like
root etc., and by actual users all at the end.
How do I do that? By creating subdirectories?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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
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
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