导读 | 下载软件包时,你可能面临这些问题:网络连接不稳定或者突然断电,这会导致安装的软件包受到损坏。那么本文将指导你如何在Linux下生成MD5校验和并使用它来校验文件。 |
在Debian/Ubuntu系统上,你可以使用debsums工具来校验已安装软件包的MD5和。如果你想在安装之前知道关于debsums软件包的信息,可以使用APT-CACHE,就像这样:
apt-cache search debsums
下一步,使用apt命令来安装它,如下所示:
sudo apt install debsums
现在可以了解如何使用debsums工具,来校验已安装软件包的MD5和了。
说明:我在下面的所有命令中使用了sudo,因为普通用户可能没有某些文件的读取权限。
此外,来自debsums命令的输出在左边显示了文件位置,在右边显示了检验结果。你会得到三种可能的结果,它们包括:
- · OKDD表明某个文件的MD5和是好的。
- · FAILEDDD表明某个文件的MD5和不匹配。
- · REPLACEDDD意味着某个特定文件已被来自另一个软件包的文件所更换。
如果你不用任何选项来运行,debsums会对照常规的md5sum文件来校验系统上的每个文件,扫描文件系统、寻找MD5和
- /usr/bin/a11y-profile-manager-indicator OK
- /usr/share/doc/a11y-profile-manager-indicator/copyright OK
- /usr/share/man/man1/a11y-profile-manager-indicator.1.gz OK
- /usr/share/accounts/providers/facebook.provider OK
- /usr/share/accounts/qml-plugins/facebook/Main.qml OK
- /usr/share/accounts/services/facebook-microblog.service OK
- /usr/share/accounts/services/facebook-sharing.service OK
- /usr/share/doc/account-plugin-facebook/copyright OK
- /usr/share/accounts/providers/flickr.provider OK
- /usr/share/accounts/qml-plugins/flickr/Main.qml OK
- /usr/share/accounts/services/flickr-microblog.service OK
- /usr/share/accounts/services/flickr-sharing.service OK
- /usr/share/doc/account-plugin-flickr/copyright OK
- /usr/share/accounts/providers/google.provider OK
- /usr/share/accounts/qml-plugins/google/Main.qml OK
- /usr/share/accounts/services/google-drive.service OK
- /usr/share/accounts/services/google-im.service OK
- /usr/share/accounts/services/picasa.service OK
- /usr/share/doc/account-plugin-google/copyright OK
- /lib/systemd/system/accounts-daemon.service OK
- /usr/lib/accountsservice/accounts-daemon OK
- /usr/share/dbus-1/interfaces/org.freedesktop.Accounts.User.xml OK
- /usr/share/dbus-1/interfaces/org.freedesktop.Accounts.xml OK
- /usr/share/dbus-1/system-services/org.freedesktop.Accounts.service OK
- /usr/share/doc/accountsservice/README OK
- /usr/share/doc/accountsservice/TODO OK
- ….
为了能够校验每个软件包的每个文件和配置文件,查找任何变化,请加入-a或–all选项:
sudo debsums --all
校验所有配置文件的MD5和:
- /usr/bin/a11y-profile-manager-indicator OK
- /usr/share/doc/a11y-profile-manager-indicator/copyright OK
- /usr/share/man/man1/a11y-profile-manager-indicator.1.gz OK
- /etc/xdg/autostart/a11y-profile-manager-indicator-autostart.desktop OK
- /usr/share/accounts/providers/facebook.provider OK
- /usr/share/accounts/qml-plugins/facebook/Main.qml OK
- /usr/share/accounts/services/facebook-microblog.service OK
- /usr/share/accounts/services/facebook-sharing.service OK
- /usr/share/doc/account-plugin-facebook/copyright OK
- /etc/signon-ui/webkit-options.d/www.facebook.com.conf OK
- /usr/share/accounts/providers/flickr.provider OK
- /usr/share/accounts/qml-plugins/flickr/Main.qml OK
- /usr/share/accounts/services/flickr-microblog.service OK
- /usr/share/accounts/services/flickr-sharing.service OK
- /usr/share/doc/account-plugin-flickr/copyright OK
- /etc/signon-ui/webkit-options.d/login.yahoo.com.conf OK
- /usr/share/accounts/providers/google.provider OK
- /usr/share/accounts/qml-plugins/google/Main.qml OK
- /usr/share/accounts/services/google-drive.service OK
- /usr/share/accounts/services/google-im.service OK
- /usr/share/accounts/services/picasa.service OK
- /usr/share/doc/account-plugin-google/copyright OK
- …
还有可能只校验配置文件,不包括软件包的其他所有文件,为此只要使用-e或–config选项:
sudo debsums --config
只校验配置文件的MD5和:
- /etc/xdg/autostart/a11y-profile-manager-indicator-autostart.desktop OK
- /etc/signon-ui/webkit-options.d/www.facebook.com.conf OK
- /etc/signon-ui/webkit-options.d/login.yahoo.com.conf OK
- /etc/signon-ui/webkit-options.d/accounts.google.com.conf OK
- /etc/dbus-1/system.d/org.freedesktop.Accounts.conf OK
- /etc/acpi/asus-keyboard-backlight.sh OK
- /etc/acpi/events/asus-keyboard-backlight-down OK
- /etc/acpi/ibm-wireless.sh OK
- /etc/acpi/events/tosh-wireless OK
- /etc/acpi/asus-wireless.sh OK
- /etc/acpi/events/lenovo-undock OK
- /etc/default/acpi-support OK
- /etc/acpi/events/ibm-wireless OK
- /etc/acpi/events/asus-wireless-on OK
- /etc/acpi/events/asus-wireless-off OK
- /etc/acpi/tosh-wireless.sh OK
- /etc/acpi/events/asus-keyboard-backlight-up OK
- /etc/acpi/events/thinkpad-cmos OK
- /etc/acpi/undock.sh OK
- /etc/acpi/events/powerbtn OK
- /etc/acpi/powerbtn.sh OK
- /etc/init.d/acpid OK
- /etc/init/acpid.conf OK
- /etc/default/acpid OK
- …
下一步,如果想在debsums的输出中只显示变化的文件,请使用-c或–changed选项。我在自己的系统中没有找到任何变化的文件。
sudo debsums --changed
下一个命令输出没有md5sum信息的文件,这里我们使用-l和–list-missing选项。在我的系统上,该命令没有显示任何文件。
sudo debsums --list-missing
现在只要指定名称,就可以校验单一软件包的md5和:
sudo debsums apache2
校验已安装软件包的MD5和:
- /lib/systemd/system/apache2.service.d/apache2-systemd.conf OK
- /usr/sbin/a2enmod OK
- /usr/sbin/a2query OK
- /usr/sbin/apache2ctl OK
- /usr/share/apache2/apache2-maintscript-helper OK
- /usr/share/apache2/ask-for-passphrase OK
- /usr/share/bash-completion/completions/a2enmod OK
- /usr/share/doc/apache2/NEWS.Debian.gz OK
- /usr/share/doc/apache2/PACKAGING.gz OK
- /usr/share/doc/apache2/README.Debian.gz OK
- /usr/share/doc/apache2/README.backtrace OK
- /usr/share/doc/apache2/README.multiple-instances OK
- /usr/share/doc/apache2/copyright OK
- /usr/share/doc/apache2/examples/apache2.monit OK
- /usr/share/doc/apache2/examples/secondary-init-script OK
- /usr/share/doc/apache2/examples/setup-instance OK
- /usr/share/lintian/overrides/apache2 OK
- /usr/share/man/man1/a2query.1.gz OK
- /usr/share/man/man8/a2enconf.8.gz OK
- /usr/share/man/man8/a2enmod.8.gz OK
- /usr/share/man/man8/a2ensite.8.gz OK
- /usr/share/man/man8/apache2ctl.8.gz OK
假设你以普通用户的身份运行debsums,没有sudo权限,那么可以使用–ignore-permissions选项,把权限错误当成警告:
debsums --ignore-permissions
-g 选项告诉debsums利用deb内容生成MD5和,其中:
- · missingDD指令debsums利用deb,为不提供MD5和的软件包生成MD5和。
- · allDD指令debsums忽视磁盘上和,使用deb文件中存在的和,或者如果没有的话,就用它生成一个。
- · keepDD指令debsums把提取/生成的和写入到/var/lib/dpkg/info/package.md5sums文件。
- · nocheckDD意味着提取/生成的和没有对照已安装软件包来进行校验。
如果你看一下目录/var/lib/dpkg/info/的内容,就会看到各个文件的md5sum,如下图所示:
cd /var/lib/dpkg/info ls *.md5sums
列出软件包的所有MD5和:
- a11y-profile-manager-indicator.md5sums
- account-plugin-facebook.md5sums
- account-plugin-flickr.md5sums
- account-plugin-google.md5sums
- accountsservice.md5sums
- acl.md5sums
- acpid.md5sums
- acpi-support.md5sums
- activity-log-manager.md5sums
- adduser.md5sums
- adium-theme-ubuntu.md5sums
- adwaita-icon-theme.md5sums
- aisleriot.md5sums
- alsa-base.md5sums
- alsa-utils.md5sums
- anacron.md5sums
- apache2-bin.md5sums
- apache2-data.md5sums
- apache2.md5sums
- apache2-utils.md5sums
- apg.md5sums
- apparmor.md5sums
- app-install-data.md5sums
- app-install-data-partner.md5sums
- …
记住:使用-g选项与–generate=missing一样,你可以试着为apache2软件包生成md5和,只要运行下面这个命令:
sudo debsums --generate=missing apache2
由于我系统上的apache2软件包已经有md5和,它会显示下列输出,这与运行$ sudo debsums apache2的结果一样。
想了解更多有意思的选项和使用方面的信息,请参阅debsums参考手册页。
man debsums
在本文中,我们介绍了如何对照MD5校验和校验已安装的Debian/Ubuntu软件包,为了避免在你的系统上安装和执行损坏的二进制文件或软件包文件,有必要对照软件包中存储的信息来校验文件系统上的文件。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/linux/105932.html