Check Verify MD5SUM Packages Files in Linux
In this article
To check and verify MD5 checksums for packages and files in Linux, use the md5sum command with the -c option to compare a file against a stored checksum, or run md5sum to generate a new checksum. This article explains the command syntax, how to verify downloaded packages, common pitfalls, and how to handle multiple files.
What Is MD5 and Why Verify It?
MD5 (Message-Digest Algorithm 5) is a cryptographic hash function that produces a 128-bit (32-character) hexadecimal string from any input. It was widely used to verify data integrity, but since 2008 it is considered cryptographically broken for security purposes (collision attacks). However, it is still commonly used for non-security integrity checks, such as verifying that a downloaded package was not corrupted during transfer.
Verifying a checksum helps you confirm that a file is exactly what the publisher intended, and that no bits were flipped due to network errors or disk issues. It does not prove authenticity—an attacker can replace both the file and the checksum. For security-critical downloads, prefer SHA-256 or GPG signatures.
How md5sum Works
The md5sum command reads a file, computes its MD5 digest, and prints the hash followed by the filename. When you use the -c (check) option, it reads a checksum file (like MD5SUMS) that contains hashes and filenames, then compares each file’s computed hash to the listed one.
Basic usage:
md5sum file.iso– prints the hash offile.iso.md5sum -c checksums.md5– verifies all files listed inchecksums.md5.md5sum *– computes hashes for all files in the current directory.
The output of a check is either OK or FAILED for each file. The exit code is 0 if all checks pass, 1 if any fail.
Verifying a Single Downloaded Package
Most Linux distributions provide checksum files alongside ISO images or packages. For example, after downloading ubuntu-22.04.iso and its MD5SUMS file, you would run:
md5sum ubuntu-22.04.iso– generates the hash of your download.- Compare the output to the hash in
MD5SUMSmanually, or md5sum -c MD5SUMS– but this only works if the filename in the checksum file matches the one in your directory.
If the checksum file uses a different filename (e.g., a relative path), you may need to edit it or use --ignore-missing to skip absent files.
Verifying Multiple Files at Once
To verify several files, create a checksum file with md5sum file1 file2 > mychecksums.md5, then later run md5sum -c mychecksums.md5. The file must be in the same directory as the files, or paths must be relative to the current working directory.
Example:
cd /path/to/downloads md5sum package1.deb package2.deb > checksums.md5 md5sum -c checksums.md5
If you move the files, update the paths in the checksum file or run the check from the directory containing them.
Common Problems and Misconceptions
- “MD5 is broken, so it’s useless” – For accidental corruption, MD5 is still fine. For security against malicious tampering, use SHA-256 or GPG.
- “The checksum doesn’t match, so the file is malicious” – It could also be a corrupted download, a wrong version, or a typo in the checksum file.
- “I can just look at the hash visually” – That is error-prone. Use
md5sum -cor a diff command. - “The file is too large for MD5” – md5sum handles files of any size, though for very large files SHA-256 is faster on modern CPUs.
A common mistake is forgetting that the checksum file must contain the exact filename as it appears on disk. If you rename a file after downloading, the check will fail even if the content is identical.
Alternatives: SHA-256 and GPG
For better security, use sha256sum (same syntax as md5sum) or verify with GPG signatures. Most Linux ISO projects now provide SHA-256 checksums, and many also offer .sig files for GPG verification. To check a SHA-256 file:
sha256sum -c SHA256SUMS
GPG verification is more robust because it uses public-key cryptography, but it requires importing the publisher’s key and verifying the trust chain. For most users, SHA-256 is a good balance of speed and security.
Safety and Best Practices
- Always download checksum files over HTTPS, not HTTP, to prevent man-in-the-middle attacks.
- Compare checksums from the official project page, not from third-party mirrors unless you trust them.
- If you are verifying a package before installation, also consider using the package manager’s built-in integrity checks (e.g.,
aptverifies GPG signatures automatically). - For critical files, use SHA-256 or GPG instead of MD5.
Frequently Asked Questions
How do I check if a file matches an MD5 checksum?
Run md5sum filename and compare the output to the expected hash. To automate, save the expected hash in a file with the format hash filename and run md5sum -c checksumfile.
What does “md5sum: WARNING: 1 computed checksum did NOT match” mean?
It means the file’s content differs from the hash in the checksum file. The file may be corrupted, incomplete, or the wrong version. Re-download the file and try again.
Can I verify an MD5 checksum on Windows or macOS?
Yes. On Windows, use certutil -hashfile file MD5 (or PowerShell’s Get-FileHash). On macOS, use md5 file. The syntax differs, but the concept is the same.
Why do some checksum files have “*” before the filename?
The asterisk indicates binary mode in GNU tools. It is part of the output format and does not affect verification. When you create a checksum file, the asterisk appears automatically.
Is MD5 still safe for verifying downloaded Linux ISOs?
For accidental corruption, yes. For security against malicious modification, no—use SHA-256 or GPG. Many distributions have moved to SHA-256, but MD5 is still seen in older packages.
How do I verify a package I installed with apt or yum?
Package managers like apt and yum verify package integrity automatically using GPG signatures. You do not need to run md5sum manually for packages installed through the official repositories.