How to Verify File Integrity Using the sha256sum Command in Linux

When you download a massive operating system ISO file (like a 4 GB Ubuntu installer) or a highly sensitive cryptographic binary, a single corrupted byte during the download process can cause catastrophic system crashes during installation. Furthermore, malicious actors often intercept network traffic and silently replace legitimate files with compromised, malware-infected versions. To mathematically guarantee that a file is 100% intact and completely unaltered, you must calculate its cryptographic hash using the sha256sum command.

How Cryptographic Hashing Works

A hashing algorithm reads every single one and zero inside a file and runs them through a complex mathematical formula. The output is a highly specific, fixed-length string of alphanumeric characters (the “hash” or “checksum”). If even a single byte of data inside the 4 GB file is altered, the resulting mathematical hash will change completely. It is virtually impossible to forge a hash.

The sha256sum command utilizes the SHA-256 algorithm, which is the modern, highly secure cryptographic standard (completely replacing the older, broken MD5 and SHA-1 algorithms).

How to Compute a Hash

To generate the mathematical checksum for a file you just downloaded (e.g., ubuntu-installer.iso), simply run the command followed by the filename:

sha256sum ubuntu-installer.iso

The kernel will read the entire 4 GB file (which may take a few seconds depending on the speed of your hard drive) and output a 64-character string of text, such as:

b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 ubuntu-installer.iso

How to Verify the File Integrity

Once you have computed the local hash, you must compare it against the official hash provided by the software developer on their secure website.

You can visually compare the two 64-character strings. If they match perfectly, character for character, you have mathematical proof that your downloaded file is flawless and completely untampered.

If you are downloading hundreds of files and checking them manually is impossible, you can automate the process. Developers often provide a text file (e.g., checksums.txt) containing the official hashes. You can instruct your Linux machine to read that text file, compute the hashes of your local files, and automatically compare them using the -c (check) flag:

sha256sum -c checksums.txt

The terminal will instantly print a clean “OK” next to every file that passes the mathematical verification, immediately flagging any files that have been corrupted or compromised.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.