GNU Core Utilities Checksum Basics for Linux

GNU Core Utilities Checksum Basics for Linux

The checksum utility in the GNU Core Utilities in Linux is a set of tools designed to calculate and verify checksums for files. These tools help ensure data integrity by allowing you to verify that files have not been altered or corrupted. The most commonly used checksum utilities are md5sum, sha1sum, sha256sum, and other variations like sha384sum and sha512sum.

Editor’s note: The article references checking checksums via sha1sum -c filename.sha1 (or md5sum -c filename.md5 etc. etc.), it is important to note that when generating a checksum via sha1sum filename (or md5sum filename etc. etc.) that this does not save the checksum to a file, to save the checksum to a file you must add > /path/to/save/.sha1 (or .md5 etc. etc.). For instance if generating the checksum of text.txt with sha256sum the entire command would be: sha256sum test.txt > test.txt.sha256. This will save the checksum to a file named test.txt.sha256 which you can then check the original file against in the future by running sha256sum test.txt.sha256. It is important to note that when you check the file against the checksum file in the future, the checksum file must have the full path to the original file.Ā 

Basic Usage of Checksum Utilities

Hereā€™s an overview of the most commonly used checksum utilities and their basic usage:

1. md5sum

Calculates and verifies MD5 checksums, which produce a 128-bit hash value.

  • Generate MD5 checksum:

md5sum filename

Output will be in the form of:

d41d8cd98f00b204e9800998ecf8427e filename

  • Verify MD5 checksum:

If you have a file filename.md5 containing the checksum:

md5sum -c filename.md5

2. sha1sum

Calculates and verifies SHA-1 checksums, which produce a 160-bit hash value.

  • Generate SHA-1 checksum:

sha1sum filename

Output will be in the form of:

da39a3ee5e6b4b0d3255bfef95601890afd80709 filename

  • Verify SHA-1 checksum:

If you have a file filename.sha1 containing the checksum:

sha1sum -c filename.sha1

3. sha256sum

Calculates and verifies SHA-256 checksums, which produce a 256-bit hash value.

  • Generate SHA-256 checksum:

sha256sum filename

Output will be in the form of:

e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 filename

  • Verify SHA-256 checksum:

If you have a file filename.sha256 containing the checksum:

sha256sum -c filename.sha256

4. sha384sum

Calculates and verifies SHA-384 checksums, which produce a 384-bit hash value.

  • Generate SHA-384 checksum:

sha385sum filename

Output will be in the form of:

6dcd4ce23d88e2ee6b9c53c680865fb39254a2a5d72c37ac4

c1d894c2f20f91b67aefecb1fda6c1a57db61d3b5c64b9e filename

  • Verify SHA-384 checksum:

If you have a file filename.sha384 containing the checksum:

sha384sum -c filename.sha384

5. sha512sum

Calculates and verifies SHA-512 checksums, which produce a 512-bit hash value.

  • Generate SHA-512 checksum:

sha512sum filename

Output will be in the form of:

cf83e1357eefb8bdf1542850d66d8007d620e40

50b5715dc83f4a921d36ce9ce47d0d13c5d85f

2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e filename

  • Verify SHA-512 checksum:

If you have a file filename.sha512 containing the checksum:

sha512sum -c filename.sha512

Common Options

  • -c or --check: Reads the checksums from a file and verifies them against the corresponding files.
  • --tag: Creates a BSD-style checksum file, which is commonly used for distributing checksums.

Example Workflow

  1. Generate a checksum and save it to a file:

sha256sum yourfile.zip > yourfile.zip.sha256

2. Verify the checksum:

sha256sum -c yourfile.zip.sha256

The output will indicate whether the checksum matches the file.

Conclusion

Checksum utilities in the GNU Core Utilities are powerful tools for ensuring data integrity. By generating and verifying checksums, you can ensure that files have not been corrupted or altered during storage or transfer. The commands md5sum, sha1sum, sha256sum, sha384sum, and sha512sum provide flexible options for various hashing algorithms, making it easy to integrate checksum verification into your workflow.

This post has been created entirely using AI and although it has been reviewed by the editor, it may not be entirely factual or all encompassing. Always be sure to complete your own research. This post is in the public domain or otherwise listed under theĀ CC0 License.