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.
What is a checksum?
Section titled “What is a checksum?”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.
Common checksum algorithms
Section titled “Common checksum algorithms”- SHA (family of algorithms including SHA-1, SHA-224, SHA-256, SHA-384, SHA-512)
Note: Always use the same algorithm for verification as was used to generate the checksum.
Generating checksums on Linux
Section titled “Generating checksums on Linux”All Ruachost.com servers run Linux, which includes command line tools for generating MD5 and SHA checksums.
- Log in via SSH.
- At the command prompt, type one of the following, replacing
filenamewith your file name:
MD5 checksum
Section titled “MD5 checksum”md5sum filename > md5sums.txtSHA checksum
Section titled “SHA checksum”- SHA-256:
sha256sum filename > sha256sums.txt- SHA-512:
sha512sum filename > sha512sums.txtThe resulting md5sums.txt or sha512sums.txt file contains the checksums.
Generating multiple checksums
Section titled “Generating multiple checksums”- For all
.zipfiles 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
md5sumwith the desired SHA command to generate SHA checksums instead.
Verifying checksums on Linux
Section titled “Verifying checksums on Linux”- Log in via SSH.
- At the command prompt, run one of the following based on your checksum file:
MD5 verification:
md5sum -c md5sums.txtSHA verification
Section titled “SHA verification”- SHA-256:
sha256sum -c sha256sums.txt- SHA-512:
sha512sum -c sha512sums.txtMatching checksums display OK, while mismatches display FAILED.
Tip: To show only mismatched checksums, use the --quiet option:
sha512sum --quiet -c sha512sums.txtOther operating systems
Section titled “Other operating systems”- Windows: Install a checksum utility program.
- macOS: Use
md5andshasumcommands in the terminal.