The article explains how you can generate file checksums and verify file integrity.
What are checksums?
A checksum that is also called a hash, is an alphanumeric value that uniquely represents the contents of a file. Checksums are mainly used to verify the integrity of files downloaded from an external source, such as an installation file. For example, you can generate checksums for your backup files, and then verify that they are not been corrupted or altered at a later date.
MD5 and SHA-1 are the two checksum algorithms that are used most commonly. While verifying checksums, you must remember that you need to use the same algorithm that was used previously to generate checksums. This is because a file with MD5 checksum value is different from its SHA-1 checksum value.
# Steps to generate Checksums
All hosting servers from MilesWeb include command-line programs that are used to generate MD5 and SHA-1 checksums.
Perform the following steps to generate a file checksum and store the value in a file:
1. Log in to the account using SSH.
2. Type the following commands, in the command prompt:
(i) Command to generate an MD5 checksum,
md5sum filename > md5sums.txt
(ii) Command to generate an SHA-1 checksum,
sha1sum filename > sha1sums.txt
Replace filename with the name of a file for which you want to generate a checksum.
Now, the md5sums.txt (or sha1sums.txt) contains a file listing and associated checksums.
Note: Generating multiple checksums at once is also possible. For example, to generate MD5 checksums for all of the .zip files in the current directory, type following command :
md5sum *.zip > md5sums.txt
Similarly, you can generate MD5 checksums for all of the files in the current directory and all the directories below it, by typing the following command :
find . -type f -exec md5sum {} > md5sums.txt \;
Replace md5sum with sha1sum to generate SHA-1 checksums instead.
# Steps to verify checksums
Perform the following steps to verify the file checksums :
1. Using SSH login to your account.
2. Type the following commands in the command prompt depending on the algorithms (MD5 or SHA-1) that were previously used to generate the checksums. In these examples filenames md5sums.txt and sha1sums.txt are used, so if you have stored the checksums in a different file, use that file name :
(i) Command to verify MD5 checksums :
md5sum -c md5sums.txt
(ii) Command to verify SHA-1 checksums :
sha1sum -c sha1sums.txt
The matching checksum will display OK, while mismatched checksum will display FAILED.
When you check a lot of files, mismatched results can get lost among all the passing results. So, to display only the mismatched checksums, use the quiet option. Example :
sha1sum --quiet -c sha1sums. txt
Note: the md5sum and sha1sum programs run on Linux operating systems. So, to generate and verify checksums on a computer that is running Apple Mac OS X, you can use the md5 and shasum programs. For the Microsoft Windows computer, you can install one of the many programs available for download to generate and verify checksum.
Also Read :