How to Verify Checksum on a File on Linux

How to Verify Checksum of a File on Linux

Spread the love

Welcome to our tutorial on how to verify checksum of a file on Linux. Maintaining the integrity and security of data in the digital realm is crucial. Checksums validate the authenticity of files and data sets by generating unique strings of characters through mathematical algorithms. We’ll delve into the fundamentals of checksums, their significance in various contexts, and how to generate and verify checksums effectively. Let’s begin our exploration!

Prerequisites:

  • A Linux server
  • SSH access

What is a Checksum?

A checksum is a mathematical algorithm used to generate an alphanumeric value for a file. This process is facilitated by specialized tools that employ cryptographic hash functions to create a hash value. Checksums are crucial in verifying the integrity and security of ZIP archives or binary files and in various file types like text or document files. A matching checksum confirms that a file maintains its digital integrity and security and is an exact replica of the original file.

Consequently, if the checksum of a downloaded file does not align with the original value, two primary reasons may account for it:

  • The file might have been tampered with by unauthorized parties.
  • The file may not have been downloaded correctly, potentially resulting in the corruption of some file elements.

The two primary checksum algorithms commonly used are MD5 and SHA. When verifying checksums, it is essential to use the same algorithm that generated them. For instance, a file’s MD5 checksum will differ significantly from its SHA-256 checksum.

Method 1 – Verify checksum using md5sum

Begin by logging into your server via SSH:

ssh root@IP_Address -p Port_number

Substitute ‘IP_Address’ and ‘Port_number’ with your server’s IP address and SSH port number. If necessary, replace ‘root’ with your account’s username.

You can generate the MD5 checksum to compare it with the original location of the file you downloaded or copied using the following command:

md5sum file_name

Substitute “file_name” with the name of your file.

Here’s how the output should appear:

# md5sum file_name
b74a5725c6bb94d2d0e527e1996dc9f5 file_name

Please be aware that the MD5 checksum value will differ because the file used in this tutorial is distinct from the one you are examining.

Additionally, you can utilize the following command to save the list of files alongside their MD5 checksums in a text file for future comparison:

md5sum file_name > md5sumlist.txt

To verify the MD5 checksum from the generated list, use the following command:

md5sum -c md5sumlist.txt

For every matching checksum, the display shows “OK,” while a mismatched checksum indicates “FAILED.” Here’s how the output should look:

# cat md5sumlist.txt
b74a5725c6bb94d2d0e527e1996dc9f5 file_name
# md5sum -c md5sumlist.txt
file_name: OK

# cat md5sumchangedlist.txt
a74a5725c6bb94d2d0e527e1996dc9f5 file_name
# md5sum -c md5sumchangedlist.txt
file_name: FAILED

Method 2 – Verify checksum using sha256sum

To start, log in to your server using SSH:

ssh root@IP_Address -p Port_number

Replace ‘IP_Address’ and ‘Port_number’ with your server’s IP address and SSH port number. If needed, replace ‘root’ with your account username.

You can generate the SHA-256 checksum to compare it with the original location of the file you downloaded or copied using the following command:

sha256sum file_name

Replace file_name with your file name.

Here’s how the output should look:

# sha256sum file_name
8f005696fff811934bf7e80be08c7c8b70899991f607294f68abb25ab65a14f9 file_name

Please note that the SHA-256 checksum value will differ because the file used in this tutorial differs from the one you’re examining.

You can also use the following command to store the list of files along with their SHA-256 checksums in a text file for future comparison:

# sha256sum file_name > sha256sumlist.txt

To verify the SHA-256 checksum from the list you have generated, use the following command:

# sha256sum -c sha256sumlist.txt

For every matching checksum, the display shows “OK,” while a mismatched checksum indicates “FAILED.” Here’s how the output should look:

# cat sha256sumlist.txt
8f005696fff811934bf7e80be08c7c8b70899991f607294f68abb25ab65a14f9 file_name
# sha256sum -c sha256sumlist.txt
file_name: OK

# cat sha256sum_changed_list.txt
3f005696fff811934bf7e80be08c7c8b70899991f607294f68abb25ab65a14f9 file_name
# sha256sum -c sha256sum_changed_list.txt
file_name: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

Method 3 – Verify checksum using sha512sum

Begin by logging into your server via SSH:

ssh root@IP_Address -p Port_number

Substitute ‘IP_Address’ and ‘Port_number’ with your server’s actual IP address and SSH port number. If necessary, replace ‘root’ with your account’s username.

You can generate the SHA-512 checksum to compare with the original location of the file you downloaded or copied using the following command:

# sha512sum file_name

Substitute “file_name” with the name of your file.

Here’s the expected output:

# sha512sum file_name
b1347fc187453bdbd70ae1f4ca8214856ee24e994ffc65544c1c9ba84d4486177029f123070d939504f56e27e1fd6c9b3f2eec4f0174fd3a35fec570fa8192f0 file_name

Please be aware that the SHA-512 checksum value will differ because the file used in this tutorial is distinct from the one you are currently examining.

Additionally, you can utilize the following command to save the list of files alongside their SHA-512 checksums in a text file for subsequent comparisons:

# sha512sum file_name > sha512sumlist.txt

To verify the SHA-512 checksum from the generated list, use the following command:

# sha512sum -c sha512sumlist.txt

For every matching checksum, the display shows “OK,” while a mismatched checksum indicates “FAILED.” Here’s how the output should look:

# cat sha512sumlist.txt
b1347fc187453bdbd70ae1f4ca8214856ee24e994ffc65544c1c9ba84d4486177029f123070d939504f56e27e1fd6c9b3f2eec4f0174fd3a35fec570fa8192f0 file_name
# sha512sum -c sha512sumlist.txt
file_name: OK

# cat sha512changedlist.txt
31347fc187453bdbd70ae1f4ca8214856ee24e994ffc65544c1c9ba84d4486177029f123070d939504f56e27e1fd6c9b3f2eec4f0174fd3a35fec570fa8192f0 file_name
# sha512sum -c sha512changedlist.txt
file_name: FAILED
sha512sum: WARNING: 1 computed checksum did NOT match

Conclusion

After trying these solutions, you shouldn’t have issues verifying checksums on Linux. If you still have trouble, however, contact our managed server support team, and we’ll make sure your files can be verified or, at the very least, tell you exactly why it’s impossible.

PS. If you found this post on verifying checksum helpful, please consider sharing it with your friends on social networks or leaving a comment in the comments section. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *