brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pwck -r checks passwd and shadow for broken entries, a read-only security check

Security
~/tips/tip-security-pwck-read-only-check

sudo pwck -r

Checks the account files for broken lines without changing a thing.

After years of adding and removing users, the account files collect odd leftovers. pwck checks /etc/passwd and /etc/shadow for them, and -r keeps it from fixing anything on its own.

I’d run it read-only first:

sudo pwck -r
echo $?
sudo grpck -r

It reports lines with the wrong number of fields, duplicate user names, users whose primary group does not exist, home folders that are missing and users that appear in one file but not the other. grpck does the same for /etc/group and /etc/gshadow.

On a stock Ubuntu install you will already see a few warnings, such as system users like lp or news whose home folder does not exist. That is normal. What to look for is an account that only exists in /etc/shadow, or a duplicate name, because both point to hand editing or something worse.

The exit code helps in scripts. 0 means all is fine, and other values mean problems were found or a file could not be read; the manual lists each one.

Be careful without -r. In normal mode pwck asks whether it should delete bad entries, and answering yes too quickly can remove an account you still need. Take a copy of the four files before you let it change anything.

Further reading: pwck(8) manual page

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link