I have many Ubuntu-powered devices around me.
As far I know /etc/group
, /etc/passwd
, /etc/shadow
are created during installation, so they do not belong to any package:
$ dpkg -S /etc/passwd
dpkg-query: no path found matching pattern /etc/passwd
$ dpkg -S /etc/shadow
dpkg-query: no path found matching pattern /etc/shadow
$ dpkg -S /etc/group
dpkg-query: no path found matching pattern /etc/group
My question is in title – How to check that my users and groups are correct?
What if I misspelled or changed something by hand in such files?
Best Answer
1. Basic approach
I found very useful package for such operation. It is named
base-passwd
and has the following description:Master files (in aforementioned terminology) are placed in:
/usr/share/base-passwd/group.master
/usr/share/base-passwd/passwd.master
The package contains only one binary
/usr/sbin/update-passwd
.Its purpose is described in man-page (
man update-passwd
):For the problem from the question we need to run:
Also you can try to run the simulation (dry-run):
Running without arguments will safely update
/etc/passwd
,/etc/shadow
and/etc/group
or quit quietly:The utility covers 39 standard groups - adm, audio, backup, bin, cdrom, daemon, dialout, dip, disk, fax, floppy, games, gnats, irc, kmem, list, lp, mail, man, news, nogroup, operator, plugdev, proxy, root, sasl, shadow, src, staff, sudo, sys, tape, tty, users, utmp, uucp, video, voice, www-data.
One can read local documentation about standard groups in
/usr/share/doc/base-passwd/users-and-groups.html
(or online).2. Deeper approach
Warning: do not continue if unsure what you are doing or if you are newbie.
Start with
and then if you have installed other software from repositories and then trashed your
/etc/passwd
and/or/etc/group
you can try to reinstall all such packages with the command based on @muru suggestion:2.1. Broken
/etc/group
If you have removed entries from
/etc/group
you will face error messages asYou need to remove corresponding lines from
/var/lib/dpkg/statoverride
and/etc/passwd
then try again with the command above.Other possible error message is
You can fix it by downloading the package manually:
and then try again with the command above.
If you have removed systemd-related groups systemd-journal, systemd-timesync, systemd-network, systemd-resolve, systemd-bus-proxy from /etc/group then remove them from
/etc/passwd
and reinstallsystemd
package withthen try again with the command above
2.2. Broken
/etc/passwd
If you have removed entries from
/etc/passwd
you will face error messages asYou need to remove corresponding line from
/var/lib/dpkg/statoverride
and then try again with the command above.