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?
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 communityYou 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
/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.sort -n -t ':' -k3 /etc/passwd | less