使用rpm -qV openssh-server
我将得到与默认值相比已更改的文件列表。
~$ rpm -qV openssh-server S.?....T. c /etc/ssh/sshd_config ~$
Ubuntu上的dpkg
可以做到这一点吗?
我不这么认为,在Ubuntu的MD5校验和只存储某些文件。 对于任何给定的包,可以find有校验和的文件列表
/var/lib/dpkg/info/<package>.md5sums
例如
/var/lib/dpkg/info/openssh-server.md5sums
这些通常不包含已经由软件包安装的文件的完整列表,例如openssh-server.md5sums
bb5096cf79a43b479a179c770eae86d8 usr/lib/openssh/sftp-server 42da5b1c2de18ec8ef4f20079a601f28 usr/sbin/sshd 8c5592e0d522fa0f8f55f3c104479ef5 usr/share/lintian/overrides/openssh-server cfcb67f58bcd1edcaa5a770863e49304 usr/share/man/man5/sshd_config.5.gz 71a51cbb514da3044b277e05a3ceaf0b usr/share/man/man8/sshd.8.gz 222d4da61fcb3c65b4e6e83944752f20 usr/share/man/man8/sftp-server.8.gz
您可以使用debsums命令(sudo apt-get install debsums)来检查具有md5签名的文件
debsums openssh-server /usr/lib/openssh/sftp-server OK /usr/sbin/sshd OK /usr/share/lintian/overrides/openssh-server OK /usr/share/man/man5/sshd_config.5.gz OK /usr/share/man/man8/sshd.8.gz OK /usr/share/man/man8/sftp-server.8.gz OK
和dpkg / 1.17.2一样,根据这个debian bug报告 ,它实现了--verify
选项。
请注意,这是对dpkg的一个相对较新的更改。 Date: Thu, 05 Dec 2013 04:56:31 +0100
在dpkg v1.17.2包中显示了这一点。
以下是对dpkg手册页中引用的--verify
操作的简要说明。
-V, --verify [package-name...] Verifies the integrity of package-name or all packages if omit‐ ted, by comparing information from the installed paths with the database metadata. The output format is selectable with the --verify-format option, which by default uses the rpm format, but that might change in the future, and as such programs parsing this command output should be explicit about the format they expect.
所以你可以使用类似yum
语法来执行validation,并以rpm格式得到结果。 例如:
dpkg --verify openssh-server
或者只使用dpkg --verify
来validation系统上安装的每一个packge。
PS
运行,在我的机器上说dpkg --verify bash
,给了我这样的东西。 (我正在运行dpkg / 1.17.5)
??5?????? c /etc/bash.bashrc ??5?????? c /etc/skel/.bashrc
似乎.deb包只包含md5sums元数据进行validation。
有工具debsums你可以检查出来。
# apt-cache search debsums debsums - tool for verification of installed package files against MD5 checksums
通常我有一个我想validation的文件列表。
所以这里有一个简单的bash函数,它可以或多或less地实现你想要的function:
dpkg-verify() { exitcode=0 for file in $*; do pkg=`dpkg -S "$file" | cut -d: -f 1` hashfile="/var/lib/dpkg/info/$pkg.md5sums" if [ -s "$hashfile" ]; then rfile=`echo "$file" | cut -d/ -f 2-` phash=`grep -E "$rfile\$" "$hashfile" | cut -d\ -f 1` hash=`md5sum "$file" | cut -d\ -f 1` if [ "$hash" = "$phash" ]; then echo "$file: ok" else echo "$file: CHANGED" exitcode=1 fi else echo "$file: UNKNOWN" exitcode=1 fi done return $exitcode }
像这样使用:
dpkg-verify /bin/ls /usr/bin/ld
在我的环境中输出:
/bin/ls: ok /usr/bin/ld: UNKNOWN
当然,编写一个类似的别名/脚本来检查特定包中的文件应该相当简单。