Checking the SHA-256 hash of a file is a reliable way to verify its integrity and ensure it has not been corrupted or tampered with. On Linux, this process is simple and can be done directly from the terminal.
Open the Terminal
- Search for Terminal in your applications menu.
Navigate to Your File
- Use the
cd(change directory) command to go to the folder where your file is located. - For example, if your file is in the Downloads folder:
cd ~/Downloads
Run the Command
- Linux systems include the sha256sum utility by default.
- Run the command:
sha256sum filename- Replace filename with the actual name of your file.
- You can type the first few characters of the file name and press Tab to auto-complete it.
Interpret the Result
- The terminal will output a 64-character alphanumeric string followed by the filename.
- Compare this string against the hash provided by the source (e.g., the website where you downloaded the file).
- If even one character differs, the file is not identical to the original.
Automate the Comparison
- If you have a
.txtfile containing the official hash, Linux can perform the comparison automatically. - Run the command:
sha256sum -c sha256.txt
What the Results Mean
- OK – The file is perfect and matches exactly.
- FAILED – The file is different, possibly corrupted or tampered with.
- WARNING: 1 computed checksum did NOT match – A summary warning if any file fails the check.
You can also run:
sha256sum -c sha256.txt --ignore-missing- The ignore missing flag is useful if the text file lists multiple files but you only downloaded one.
Common Use Case: Verifying ISOs
- When downloading a Linux distribution (e.g., Arch), developers usually provide a file named SHA256SUMS.
- Download your ISO and the SHA256SUMS file into the same folder, then run:
cd ~/Downloadssha256sum -c sha256sums.txt --ignore-missing
Why SHA-256?
The SHA-256 (Secure Hash Algorithm 256-bit) is a cryptographic hash function that generates a unique fingerprint for a file. It is mathematically infeasible for two different files to produce the same hash. Even a minor change, such as altering a single comma in a large text file, results in a completely different SHA-256 string.
By checking the SHA-256 hash of your files, you can ensure their authenticity and integrity. This simple verification step helps protect against corruption and tampering, making it an essential practice for Linux users.
