Sometimes an installed package or software may not work as expected. In fact, sometimes it may not even start properly. In such cases, it may be that the package file that you downloaded may be corrupted or incomplete. This can happen if there are any network related issues during file transfer. Therefore it is important to verify the integrity of downloaded package file, before you install it on your system. This is done by calculating checksum of downloaded file and comparing it with the one provided by package provider on their site. Typically, these are MD5 checksums. In this article, we will learn how to checkMd5 checksum of installed packages in Ubuntu/Debian Linux.
How to Check MD5 Checksum of Installed Packages in Ubuntu/Debian Linux
On Ubuntu/Debian systems, you can use debsums tool to check MD5 checksum of installed packages. You can run the following command to learn more about this package.
$ apt-cache search debsums
Here is the command to install debsums on your system.
$ sudo apt install debsums
Once you have installed debsums, you can run it with the following command.
$ sudo debsums
It will read the MD5 checksum of each package on your system, and compare it with their original ones, provided on each package’s site. The output of above command will list all installed packages, along with their checksum status, which can have any of the 3 values –
- OK – indicates that a file’s MD5 sum is good.
- FAILED – shows that a file’s MD5 sum does not match.
- REPLACED – means that the specific file has been replaced by a file from another package.
Here is a sample output of above command.
/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 ....
The above command checks MD5 checksum of all packages. If you want to check the MD5 checksum of specific package such as apache, then mention it after the debsum command, as shown below.
$ sudo debsums apache2
If you want to check only configuration files and exclude other files, use –config or -e option.
$ sudo debsums --config /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 ...
If you want to check MD5 checksum of all files present in all packages, use –all option.
$ sudo debsums --all /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 ...
If you want to display only the changed files in output, use –changed option.
$ sudo debsums --changed
Some packages and files may not have MD5 checksum information available. To list all such files & packages, use -l and –list-missing options.
$ sudo debsums --list-missing
Typically, you need to run debsums as user with sudo privileges. If you want to run this command as a regular user without sudo permissions, then use –ignore-permissions option.
$ debsums --ignore-permissions
debsum can also be used to generate MD5 checksums for packages. You can use -g or –generate option for this purpose. This option takes 4 values
- missing – instruct debsums to generate MD5 sums from the deb for packages which don’t provide one.
- all – directs debsums to ignore the on disk sums and use the one present in the deb file, or generated from it if none exists.
- keep – tells debsums to write the extracted/generated sums to /var/lib/dpkg/info/package.md5sums file.
- nocheck – means the extracted/generated sums are not checked against the installed package.
Here is an example command to generate checksum for apache2 package.
$ sudo debsums --generate=missing apache2
If the specified package already has an MD5 checksum present, the above command will show an output that is same as running
$ sudo debsums apache2
Typically, /var/lib/dpkg/info folder stores the MD5 checksum of all packages. You can view the list with the following commands.
$ cd /var/lib/dpkg/info $ ls *.md5sums
In this article, we have learnt how to check MD5 checksums of packages installed on your system, as well as generate MD5 checksums for packages which are missing this information.
Also read:
How to Check Bad Sectors in HDD in Ubuntu
How to Encrypt & Decrypt Files Using OpenSSL
How to Add New SSH key in GitHub
pgAdmin Connect via SSH Tunnel
How to Connect to PostgreSQL Server via Tunnel