Skip to content

Generating and verifying file checksums on Linux

Learn what a checksum is, how to generate MD5 and SHA checksums, and how to verify file integrity on Linux.

A checksum (or hash) is an alphanumeric value that uniquely represents the contents of a file. Checksums are commonly used to:

  • Verify the integrity of files downloaded from external sources.
  • Ensure your own files, such as backups, haven’t been corrupted or altered.

If two checksum values match, the files are identical.

Note: Always use the same algorithm for verification as was used to generate the checksum.

All Ruachost.com servers run Linux, which includes command line tools for generating MD5 and SHA checksums.

  1. Log in via SSH.
  2. At the command prompt, type one of the following, replacing filename with your file name:
md5sum filename > md5sums.txt
  • SHA-256:
sha256sum filename > sha256sums.txt
  • SHA-512:
sha512sum filename > sha512sums.txt

The resulting md5sums.txt or sha512sums.txt file contains the checksums.

  • For all .zip files in the current directory:
md5sum *.zip > md5sums.txt
  • For all files in the current directory and subdirectories:
find . -type f -exec md5sum {} > md5sums.txt \;

Replace md5sum with the desired SHA command to generate SHA checksums instead.

  1. Log in via SSH.
  2. At the command prompt, run one of the following based on your checksum file:

MD5 verification:

md5sum -c md5sums.txt
  • SHA-256:
sha256sum -c sha256sums.txt
  • SHA-512:
sha512sum -c sha512sums.txt

Matching checksums display OK, while mismatches display FAILED.

Tip: To show only mismatched checksums, use the --quiet option:

sha512sum --quiet -c sha512sums.txt
  • Windows: Install a checksum utility program.
  • macOS: Use md5 and shasum commands in the terminal.