Knowledge Base

Working with file checksums

This article describes how to generate file checksums and verify file integrity.

About checksums

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 verify they have not become corrupted or altered at a later date.

The two most commonly used checksum algorithms are MD5 and SHA-1. 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 different from its SHA-1 checksum value.

Generating checksums

All A2 Hosting servers include command line programs for generating MD5 and SHA-1 checksums.

To generate a file checksum and store the value in a file, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type one of the following commands, replacing filename with the name of the file for which you want to generate a checksum:
    • To generate an MD5 checksum, type:
      md5sum filename > md5sums.txt
    • To generate an SHA-1 checksum, type:

      sha1sum filename > sha1sums.txt

    The md5sums.txt (or sha1sums.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 \;

    You can replace md5sum with sha1sum to generate SHA-1 checksums instead.

Verifying checksums

All A2 Hosting servers include command line programs for verifying MD5 and SHA-1 checksums.

To verify file checksums, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type one of the following commands based on the algorithm (MD5 or SHA-1) that was used to generate the checksums. These examples use the filenames md5sums.txt and sha1sums.txt; if you stored the checksums in a different file, use that filename instead.
    • To verify MD5 checksums, type:
      md5sum -c md5sums.txt
    • To verify SHA-1 checksums, type:

      sha1sum -c sha1sums.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 among all of the passing results. To display only mismatched checksums, use the —quiet option. For example:

    sha1sum --quiet -c sha1sums.txt
The md5sum and sha1sum programs run on Linux operating systems. To generate and verify checksums on a computer running Apple Mac OS X, you can use the md5 and shasum programs. For a computer running Microsoft Windows, you can install one of the many programs available for download that generate and verify checksums.