Verify installed files against packages: debsums and rpm -V
Check packaged files with debsums or dpkg --verify on Ubuntu and rpm -V on Rocky 9. A changed binary, config file and deleted file show what each reports.
To find out whether files installed from a package were changed later, compare them with the checksums the package manager recorded at install time. Ubuntu has debsums (extra package) and dpkg --verify (built in); Rocky has rpm -V. In the same package (openssh-client / openssh-clients), three things were changed on purpose:
- One byte appended to the binary
/usr/bin/ssh-keyscan - One line added to the config file
/etc/ssh/ssh_config /usr/bin/ssh-copy-iddeleted (on Rocky,/usr/bin/scpalso set to mode 700)
[1] Install debsums on Ubuntu and confirm the package is clean first. -s prints only problems.
$ sudo apt install debsums$ debsums -s openssh-clientBefore the changes it printed nothing and exited 0.
[2] Check again after the changes. Config files are skipped by default, so only the binary and the deletion show up:
$ debsums -s openssh-clientdebsums: missing file /usr/bin/ssh-copy-id (from openssh-client package)debsums: changed file /usr/bin/ssh-keyscan (from openssh-client package)The exit code was 2. Per the man page, 2 means changed or missing files and 1 means a package name that is not installed. Use that in scripts.
[3] Add -a to include config files, or -e for config files only. -c prints just the changed file names to stdout.
$ debsums -a -s openssh-clientdebsums: missing file /usr/bin/ssh-copy-id (from openssh-client package)debsums: changed file /usr/bin/ssh-keyscan (from openssh-client package)debsums: changed file /etc/ssh/ssh_config (from openssh-client package)$ debsums -ce openssh-client/etc/ssh/ssh_configAdmins are expected to edit config files, so review those separately from binary changes.
[4] Without debsums, use dpkg --verify. Its output uses the rpm format, and c marks config files.
$ dpkg --verify openssh-client??5?????? c /etc/ssh/ssh_configmissing /usr/bin/ssh-copy-id??5?????? /usr/bin/ssh-keyscanmissing /usr/share/doc/openssh-client/NEWS.Debian.gz…5 means the checksum differs, ? means the check was not performed; as the dpkg man page says, only the content checksum is actually checked today. The 20 missing lines under /usr/share/doc/ and /usr/share/man/ exist because the Docker ubuntu image is configured to skip docs and man pages; a regular server will not show them. Note that this command exited 0 even with changed files. For scripted checks, count output lines or use the debsums exit code.
[5] On Rocky 9, use rpm -V. Before the changes it printed nothing; afterwards (exit code 1):
$ rpm -V openssh-clientsS.5....T. c /etc/ssh/ssh_config.M....... /usr/bin/scpmissing /usr/bin/ssh-copy-idS.5....T. /usr/bin/ssh-keyscan| Letter | Meaning (rpm man page) | In this test |
|---|---|---|
S | Size differs | Line added, byte appended |
M | Mode differs (permissions, type) | chmod 700 scp |
5 | Digest differs | Content changed |
T | mTime differs | Content changed |
c | Config file (%config) | ssh_config |
. | Test passed |
rpm -qc openssh-clients lists a package's config files. If many files differ only in time, --nomtime drops the T check.
[6] Decide how to act on each result.
| Output | Action |
|---|---|
Only config files (c) changed | Match against your change records |
5 on binaries or libraries | Find out who changed them, then reinstall (sudo apt install --reinstall <pkg>, sudo dnf reinstall <pkg>) |
missing | Confirm it was an accident, then reinstall |
M only | Restore package permissions (on Rocky, rpm --setperms <pkg>) |
How a reinstall treats a modified config file differs by package and tool, so copy the file from /etc first (reinstalls were not tested here).
[7] Know the limits as a security check. Both tools compare against the package database on the same system. The debsums man page describes it as a way to find admin modifications or media errors and of limited use as a security tool; the dpkg man page also says --verify is an integrity check, not a security verification. If you suspect an intrusion, check from clean boot media or use a dedicated integrity tool. For auditing setuid files, see find setuid files.