MD5 (Message-Digest algorithm 5) can be used effectively to verify files integrity and authenticity by computing and checking MD5 hashes.

In Windows: MD5summer can be used to perform the task.

While in Linux: The famous md5sum utility is usually used.


The following examples shows how md5sum can be used from the command line.

To compute the MD5 sum of an ISO file for example use:

md5sum filename.iso

The result will be something like:

f8c7451b0de5a1e5f7a68fb3d15f4064 filename.zip

Note that the wild card can be used too, so if you are in a folder containing many files, you can compute the hashes to all files using:

md5sum *

or

md5sum h*.exe

Some applications/distributions provide a file with all MD5 hashes of the released files. Ubuntu for example provide a file called MD5SUMS and it looks like this from inside:


836440698456aa2936a4347b5485fdd6 *ubuntu-9.10-alternate-amd64.iso
3faa345d298deec3854e0e02410973dc *ubuntu-9.10-alternate-i386.iso
dc51c1d7e3e173dcab4e0b9ad2be2bbf *ubuntu-9.10-desktop-amd64.iso
d91659de6e945dbb96eb8970b2b4590a *ubuntu-9.10-desktop-armel+dove.img
297875d2a7531824a0fb08f241d33e85 *ubuntu-9.10-desktop-armel+imx51.img
8790491bfa9d00f283ed9dd2d77b3906 *ubuntu-9.10-desktop-i386.iso
ed6e77587b87fe0d92a2f21855869f00 *ubuntu-9.10-netbook-remix-i386.iso
14707e8847b9c9ba2dd1869fb5086e4f *ubuntu-9.10-server-amd64.iso
55618ad5f180692f9dac20cbff352634 *ubuntu-9.10-server-i386.iso
37a04db193b1a342f961f59aea2fada8 *wubi.exe

Now assume you downloaded: ubuntu-9.10-alternate-i386.iso
You can verify it’s hash against that list with the following command:

md5sum ubuntu-9.10-alternate-i386.iso -c MD5SUMS

If the comparison results in a single match then your file is alright.

To cultivate the result, use the following to show the positive match only:

md5sum ubuntu-9.10-alternate-i386.iso -c MD5SUMS | grep -v "FAILED$"

grep -v “FAILED$” is used to ignore the failed comparisons in the results, hence, if we change it to grep -v “OK$” we can get the failed comparisons only. this is useful when you run md5sum to verify many files against a list and need to check if there are any bad files.

One Response to “MD5 checksums to verify files integrity”

Leave a Reply

*

Haider’s WebSpace
Welcome to my technical blog. This is where I write, archive and share computer related articles. Subjects vary from posting technical solutions to researching particular topics. Feel free to comment and talk IT!
Sponsored Links
My Tweets