HackBlue

Tools · Cryptography and passwords in practice · 04 / 20

Verifying file integrity with SHA-256 checksums on Linux, macOS, and Windows

Compute and verify SHA-256 checksums for downloads and evidence, use checksum files, and understand why a checksum from the same site is weaker than a signed one.

8 min read · practice only with authorization

What a checksum proves

A cryptographic hash such as SHA-256 maps a file to a fixed 256-bit value. Changing any bit changes the hash unpredictably. If your computed hash matches a trusted published value, the file is the same one the publisher hashed. The weakness is trust in the published value: if an attacker can replace the download, they may also replace the checksum on the same page. Signatures, covered in the GPG lesson, solve that.

Commands per platform

Linux has sha256sum, macOS has shasum -a 256, and Windows has Get-FileHash in PowerShell and certutil -hashfile. Checksum files list one hash and file name per line and can be checked in one step.

Snippet
# Linux
sha256sum ubuntu.iso
sha256sum -c SHA256SUMS --ignore-missing
# macOS
shasum -a 256 ubuntu.iso
shasum -a 256 -c SHA256SUMS
# Windows PowerShell
Get-FileHash .\ubuntu.iso -Algorithm SHA256
(Get-FileHash .\ubuntu.iso).Hash -eq 'EXPECTEDHASHVALUE'
certutil -hashfile ubuntu.iso SHA256

Lab: verify a real download

Download a small official release, such as a command-line tool from its GitHub releases page that publishes a checksums file. Verify it with sha256sum -c. Then copy the file, change one byte with a hex editor or printf, and verify again to see the failure. Finally, hash a directory of evidence files into a manifest and re-verify it later.

Snippet
printf '\x00' | dd of=copy.bin bs=1 seek=100 count=1 conv=notrunc
sha256sum original.bin copy.bin
find evidence/ -type f -exec sha256sum {} + > manifest.sha256
sha256sum -c manifest.sha256

Algorithm choice

Use SHA-256 or stronger (SHA-512, SHA3-256, BLAKE2/BLAKE3). MD5 and SHA-1 have practical collision attacks, which means someone can create two different files with the same hash; they are still seen in legacy tools but should not be trusted for security decisions.

Diagram

Checksum only versus signed checksums

Who vouches for the hash?

Checksum on the same page

Detects. Corruption, mirror tampering

Fails if. Attacker controls the site and edits both

Trust anchor. The website

Signed checksum file

Detects. Corruption and tampering

Fails if. Signing key is compromised

Trust anchor. Publisher’s verified public key

Check yourself

1. Which command verifies files against a SHA256SUMS list on Linux?

2. Why is a checksum published on the same site as the download a weaker guarantee?

3. Why avoid MD5 for integrity decisions?