sha256sum and md5sum: Verify Checksums in Linux

By 

Updated on

8 min read

Verifying file integrity with sha256sum and md5sum in Linux

When you download an ISO image, a backup archive, or a large release tarball, there is no easy way to tell by looking whether the file arrived intact. A single flipped bit can break a boot image or turn a compressed archive into junk, and a compromised mirror can serve a tampered file that looks legitimate. The fix is to compare a cryptographic fingerprint of the file against a value the publisher has signed or posted somewhere you trust.

This guide shows how to use sha256sum and md5sum to generate, compare, and verify checksums on Linux, and when to use each one.

sha256sum and md5sum Syntax

Both commands follow the same form:

txt
sha256sum [OPTIONS] [FILE]...
md5sum    [OPTIONS] [FILE]...

Without options, each command prints a hex digest followed by two spaces and the file name. Pass -c to verify files against a list of previously generated checksums.

sha256sum vs md5sum

The two tools do the same job: they read a file and print a fixed-length fingerprint. The difference is the algorithm and, by extension, how safe the result is against intentional tampering.

md5sum uses the MD5 algorithm and produces a 128-bit digest. MD5 is fast but has been broken for years: it is possible to construct two different files that share the same MD5 hash. Treat it as a checksum for accidental corruption only, not for authenticity or security.

sha256sum uses SHA-256 from the SHA-2 family and produces a 256-bit digest. It is the default choice for verifying downloads, release artifacts, and anything where the threat model includes a malicious middle party. Most Linux distributions publish SHA256SUMS files next to their ISO images for exactly this reason.

When in doubt, use sha256sum. Reach for md5sum only when a publisher provides MD5 values and nothing stronger, or when you need quick parity checks between known-good files.

Generating a Checksum for a File

To produce a SHA-256 digest for a single file, pass it as an argument:

Terminal
sha256sum ubuntu-24.04.4-desktop-amd64.iso
output
3a4c9877b483ab46d7c3fbe165a0db275e1ae3cfe56a5657e5a47c2f99a99d1e  ubuntu-24.04.4-desktop-amd64.iso

The output is one line: the hex digest, two spaces, and the file name. The same file always produces the same digest, so you can run the command again after a copy or a download and compare the values by eye.

md5sum behaves the same way. Here it hashes a local archive:

Terminal
md5sum backup-2026-04-01.tar.gz
output
2e3720b76b2f9f96edc43ec4d87d7d52  backup-2026-04-01.tar.gz

Notice that the MD5 digest is shorter. That is the 128-bit hash encoded in 32 hex characters, compared with 64 hex characters for SHA-256.

Generating Checksums for Multiple Files

Both commands accept any number of file arguments and print one line per file:

Terminal
sha256sum *.tar.gz
output
b2b09c1e04b2a3a4c5d6e7f890123456789abcdef0123456789abcdef0123456  backup-2026-04-01.tar.gz
c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8  backup-2026-04-08.tar.gz

To save the output to a checksum file that you can share or verify later, redirect it:

Terminal
sha256sum *.tar.gz > SHA256SUMS

The resulting SHA256SUMS file can be published alongside the archives, and anyone who downloads them can run a single command to confirm that their copy matches.

Verifying a File Against a Known Checksum

The most common task is to check that a download matches the digest the publisher posted. Distributions usually ship a SHA256SUMS file that lists every release file and its digest. Change into the directory that holds both the archive and the checksum file, then pass -c:

Terminal
sha256sum -c SHA256SUMS
output
ubuntu-24.04.4-desktop-amd64.iso: OK
ubuntu-24.04.4-live-server-amd64.iso: OK

sha256sum reads each line of SHA256SUMS, recomputes the digest for the named file, and prints OK when they match. Any line whose file is missing or whose digest differs prints a clear error and causes the command to exit with a non-zero status, which is convenient in scripts.

When you only care about one file out of many, grep the relevant line into the check:

Terminal
grep "ubuntu-24.04.4-desktop-amd64.iso" SHA256SUMS | sha256sum -c -

The trailing - tells sha256sum to read the checksum list from standard input. This keeps the verification scoped to a single file without creating a second checksum file.

Comparing a File to a Published Digest

Sometimes the publisher does not provide a full SHA256SUMS file but instead shows a single digest on a release page. You can compare it directly without creating a file:

Terminal
echo "3a4c9877b483ab46d7c3fbe165a0db275e1ae3cfe56a5657e5a47c2f99a99d1e  ubuntu-24.04.4-desktop-amd64.iso" | sha256sum -c -
output
ubuntu-24.04.4-desktop-amd64.iso: OK

sha256sum prints two characters between the digest and the file name: a space followed by a second space for text mode, or a space followed by * for binary mode. Ubuntu’s SHA256SUMS file uses the * form, and -c accepts either one. When you paste a digest by hand, keep one of those two separators so the line parses cleanly.

Quiet and Warn Modes

During an automated check, the per-file OK lines can be noisy. The --quiet option suppresses successful lines so only failures appear:

Terminal
sha256sum -c --quiet SHA256SUMS

If every file passes, the command prints nothing and exits with status 0. If a file fails, you see a single failure line and a non-zero exit status, which fits well in a CI job or a backup script.

To flag lines in a checksum file that are not formatted correctly, add --warn. This is helpful when the file was assembled by hand and you want to be sure every entry parses.

Common Options

The flags below are the ones you are likely to use day to day:

  • -c, --check - Read digests from a file and verify each one.
  • -b, --binary - Mark files with * in the output. On Linux, reading is identical in both modes.
  • -t, --text - Read files in text mode, the default on Linux.
  • --quiet - Suppress OK lines when checking.
  • --status - Print nothing; rely on the exit status alone.
  • --ignore-missing - Skip files listed in the digest file that are not present.
  • --tag - Output BSD-style tagged format, useful when mixing hash algorithms.

md5sum accepts the same flags, which makes it easy to swap one command for the other when the algorithm changes.

Verifying an Ubuntu ISO Download

On Ubuntu, the trusted image-signing keys are available in /usr/share/keyrings/ubuntu-archive-keyring.gpg. Download the ISO, checksum list, and detached signature with wget , then verify the signature before checking the ISO:

Terminal
wget https://releases.ubuntu.com/24.04/ubuntu-24.04.4-desktop-amd64.iso
wget https://releases.ubuntu.com/24.04/SHA256SUMS
wget https://releases.ubuntu.com/24.04/SHA256SUMS.gpg
gpgv --keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg SHA256SUMS.gpg SHA256SUMS
sha256sum -c --ignore-missing SHA256SUMS

The gpgv command must report a good signature before you trust the checksums. The --ignore-missing flag then keeps the checksum test focused on the ISO you downloaded instead of failing on every other release listed in SHA256SUMS.

On another distribution, follow Canonical’s image verification instructions to obtain and authenticate the Ubuntu signing key before running gpgv. For more background on keys and signatures, see the GPG guide .

Quick Reference

For a printable quick reference, see the sha256sum cheatsheet .

CommandDescription
sha256sum file.isoGenerate a SHA-256 checksum for one file
md5sum file.isoGenerate an MD5 checksum for one file
sha256sum *.tar.gz > SHA256SUMSSave checksums for multiple files
sha256sum -c SHA256SUMSVerify files against a checksum list
grep "file.iso" SHA256SUMS | sha256sum -c -Verify one file from a larger checksum list
sha256sum -c --quiet SHA256SUMSShow only failures during verification
sha256sum -c --ignore-missing SHA256SUMSVerify only the files that are present

Troubleshooting

Checksum mismatch on a freshly downloaded file
Re-download the file, ideally from a different mirror. The most common cause is a truncated transfer or a network error. If the second download still fails, the file on the mirror may be stale or tampered with, and you should report it to the project.

No such file or directory when running with -c
The names in the checksum file are resolved relative to the current directory. Change into the directory that holds the files, or edit the checksum file to use paths that match where the files live.

improperly formatted checksum line warnings
A digest with the wrong length, a missing file name, or stray text can trip the parser. Recreate the list with a command such as sha256sum file.iso > SHA256SUMS. Current GNU Coreutils accepts Windows CRLF line endings, but older or non-GNU implementations may require dos2unix SHA256SUMS first.

The MD5 digest matches but you still do not trust the file
You are right to be cautious. MD5 collisions are practical, so match an MD5 against accidental corruption only. Ask the publisher for a SHA-256 digest or a signed checksum file.

FAQ

Which is faster, sha256sum or md5sum?
md5sum is faster, sometimes noticeably so on large files. The speed difference rarely matters on modern hardware, and it is not a good reason to pick MD5 over SHA-256 for security-sensitive checks.

Can I use sha256sum on a directory?
Not directly. Hash tools operate on files. To produce a digest that represents an entire directory, pipe a deterministic listing such as find ... -type f -print0 | sort -z | xargs -0 sha256sum through another sha256sum. The xargs guide explains how the argument passing works.

Where do I find the expected digest for a Linux distro ISO?
Most major distributions publish a checksum file or individual digest next to their ISO downloads, but the names vary. Look for files such as SHA256SUMS, CHECKSUM, or names ending in .sha256, and prefer signed checksums from the distribution’s official download page.

Is sha256sum available by default on Linux?
Both commands are available by default on most mainstream Linux distributions. GNU implementations ship in the coreutils package, while BusyBox-based systems may provide compatible sha256sum and md5sum applets instead.

Conclusion

sha256sum should be the default for verifying downloads and backups, with md5sum reserved for quick corruption checks when the publisher provides nothing stronger. When you pair a SHA-256 digest with a signed checksum file and a trusted key, you can answer the question that matters most: did I get the file the publisher actually shipped?

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page