How to generate and verify file checksums on Linux – A2 Hosting

This article describes how to generate MD5 and SHA file checksums and check file integrity on Linux.

What is a checksum?

A checksum (also called 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 hash utility to ensure that they have not been 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 should make sure that you use the same algorithm that was used to generate the checksum. For example, the MD5 checksum value of a file is completely different from its SHA-256 checksum value.

All

A2 Hosting servers run Linux and therefore include command-line programs to generate MD5 and SHA 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 file name 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 a SHA checksum, type the command name for the hash algorithm you want to use. For example, to generate a SHA-256 checksum, use the sha256sum command. To generate a SHA-512 checksum, you must type the following command:

      sha512sum filename >

    sha512sums.txt

    The md5sums.txt (or sha512sums.txt) file now contains a list of files and associated checksums.

All

A2 Hosting servers run Linux and therefore include command-line programs

to verify MD5 and SHA checksums. To check file checksums,

follow these steps:

Log in to your account using SSH. At the command prompt, type one of the following commands based on

  1. the algorithm (MD5 or SHA) that was used to generate the checksums. These examples use the file names md5sums.txt and sha512sums.txt. If you stored checksums in a different file, use that file name instead. To verify MD5 checksums, type
    • : md5sum -c md5sums.txt
    • To verify SHA checksums, type the command name for the hash algorithm you want to use. For example, to verify a SHA-256 checksum, use the sha256sum command. To verify a SHA-512 checksum, you must type the following command:

      sha512sum -c sha512sums.txt

    Each matching checksum displays

    OK, while a mismatched checksum displays FAILED.

Other

operating systems You can generate and verify checksums

on other operating systems:

For

  • a computer running Microsoft Windows, you can install one of the many downloadable programs that generates and verifies checksums
  • .

  • For a computer running Apple macOS, you can use the md5 and shasum programs on the command line.

More

information For more information about

  • the MD5 hashing algorithm, see https://en.wikipedia.org/wiki/MD5. For
  • more information about the SHA family of hashing algorithms, see https://en.wikipedia.org/wiki/Secure_Hash_Algorithms.

Contact US