This article describes how to generate MD5 and SHA file checksums and verify file integrity on Linux.
A checksum (also sometimes referred to as a hash) is an alphanumeric value that uniquely represents the contents of a file. Checksums are often used to verify the integrity of files downloaded from an external source, such as an installation file. You can also use checksums to verify the integrity of your own files. For example, you can generate checksums for your backup files and then use checksum algorithms or a hashing utility to ensure they have not become corrupted or altered at a later date. If both checksums are the same, the files are the same.
The two most commonly used checksum algorithms are MD5 and SHA. When verifying checksums, you must make sure you use the same algorithm that was used to generate the checksum. For example, a file's MD5 checksum value is completely different from its SHA-256 checksum value.
“SHA” is an umbrella term for an entire family of hashing algorithms. The two most commonly used SHA algorithms are:
All A2 Hosting servers run Linux, and therefore include command line programs for generating MD5 and SHA checksums.
To generate a file checksum and store the value in a file, follow these steps:
md5sum filename > md5sums.txt
To generate an SHA checksum, type the name of the command for the hashing algorithm you want to use. For example, to generate a SHA-256 checksum, use the sha256sum command. To generate a SHA-512 checksum, you would type the following command:
sha512sum filename > sha512sums.txt
The md5sums.txt (or sha512sums.txt) file now contains a file listing and associated checksums.
You can also generate multiple checksums at once. For example, to generate MD5 checksums for all of the .zip files in the current directory, type the following command:
md5sum *.zip > md5sums.txt
Similarly, to generate MD5 checksums for all of the files in the current directory and all directories beneath it, type the following command:
find . -type f -exec md5sum {} > md5sums.txt \;
To generate SHA checksums instead, replace md5sum with the appropriate SHA command.
All A2 Hosting servers run Linux, and therefore include command line programs for verifying MD5 and SHA checksums.
To verify file checksums, follow these steps:
md5sum -c md5sums.txt
To verify SHA checksums, type the name of the command for the hashing algorithm you want to use. For example, to verify a SHA-256 checksum, use the sha256sum command. To verify a SHA-512 checksum, you would type the following command:
sha512sum -c sha512sums.txt
Each matching checksum displays OK, while a mismatched checksum displays FAILED.
If you are checking a lot of files, mismatched results can get lost amongst all of the scrolling results. To display only mismatched checksums, use the —quiet option. For example:
sha512sum --quiet -c sha512sums.txt
You can generate and verify checksums on other operating systems:
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.