Check /etc/passwd and /etc/group with pwck and grpck

Check /etc/passwd and /etc/group with pwck and grpck

Check /etc/passwd and /etc/group with pwck and grpck

the pwck and grpck are great tools for checking to verify your local accounts/groups are in order, and there are no duplicates. Sadly, most UNIX admins don’t learn to use this tool until after they have already made a mistake. Misktakes happen by manually modifying the /etc/passwd and /etc/group files, rather than the built in utilities of “groupadd” and “useradd”

Let’s get started, login, and su to root

Root shell prompt on the server before running pwck

PWCK:

the first thing we want to use is pwck, this checks the /etc/passwd as well as the /etc/shadow file for issues, issue the following command:

Same screenshot: empty root prompt, shown where the pwck command is introduced

you should see the following:

pwck output: home directories for adm, uucp, gopher, ftp and saslauth do not exist, pwck: no changes

this is a bit confusing because it lists things that usually do not exist as errors. According to the man page, the -q option shows us errors only, rather than misc directory issues, for most cases this is a good way to test, but it’s helpful to know what the standard output looks like

pwck -q typed at the root prompt to report only real errors

So IF users on your local system are configured properly, and you run pwck, you should recieve the following:

pwck -q returning no output on a clean passwd and shadow file

a blank line. IF you have a user, or users configured properly, usually due to bad administration, you would see something similar:

pwck -q: duplicate password entry, asking to delete line test50:x:5016:5016::/home/test50:/bin/bash

as you can see, the user “test50” has been accidently entered twice, most likely by editing the /etc/passwd file, and not running pwck once completed. You can choose to delete the line here, or manually delete the improper enter from the file once the issue has been reconciled.

grpck:

The second tool grpck is a nice additional tool to check local group integrity, it works along the same lines.

if you run grpck and there are no issues, then you will be returned to the # prompt

grpck returning straight to the prompt when /etc/group has no problems

if there is an issue, you will see something like the following:

grpck: duplicate group entry, asking to delete line test911:x:6525:

should you choose to hit yes to resolve the prolem now, it will fix the problem.

grpck after answering y: delete line test911, grpck: the files have been updated

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Understanding Linux File Permissions | 16 usermod Command Examples for Linux User Administration

Leave a Reply

Your email address will not be published. Required fields are marked *