Operations 7 min read

How to Verify File Integrity with MD5 and SHA‑512 Checksums on Linux

This guide explains the principles of MD5 and SHA‑512 checksums, demonstrates how to generate and compare them using md5sum and sha512sum commands, and shows practical steps to ensure files remain unchanged during transfer or storage on Linux systems.

Raymond Ops
Raymond Ops
Raymond Ops
How to Verify File Integrity with MD5 and SHA‑512 Checksums on Linux

Introduction

Ensuring data integrity when downloading, transferring, or backing up files is essential. This article introduces how to use the MD5 algorithm and the sha512sum checksum utility to verify file integrity.

MD5 Algorithm Overview

MD5 (Message‑Digest Algorithm 5) produces a 128‑bit (16‑byte) hash value, typically displayed as a 32‑character hexadecimal string. It is widely used for integrity checks because it is fast, produces a fixed‑size output, and changes dramatically with any modification to the input.

Compressibility: output length is constant regardless of input size.

Ease of computation.

Modification resistance: small changes yield different hashes.

Collision resistance: finding a different input with the same hash is difficult.

Although MD5 has known cryptographic weaknesses, it remains sufficient for simple integrity verification.

What Is a Checksum?

A checksum is a short, fixed‑size bit sequence derived from data using a specific algorithm. Any alteration in the input data results in a significantly different checksum, making it useful for detecting transmission or storage errors.

By comparing a file’s original checksum with a newly computed one, you can determine whether the file has been altered.

Both MD5 (128‑bit) and SHA‑512 (512‑bit) can generate checksums, with SHA‑512 offering higher security.

Using MD5 and sha512sum to Verify File Integrity

Assume you have a file calico.yaml that you want to send securely.

root@k8scludes1:~# ls
calico.yaml

Generate its MD5 checksum:

root@k8scludes1:~# md5sum calico.yaml
9cc4a633f4ba45f0fd723512ec60f330  calico.yaml

Transfer the file to another machine (e.g., using scp):

root@k8scludes1:~# scp calico.yaml 192.168.110.131:/root/test/

On the destination machine, verify the file exists:

[root@etcd2 test]# ls
calico.yaml

Compute the checksum again on the destination:

[root@etcd2 test]# md5sum calico.yaml
9cc4a633f4ba45f0fd723512ec60f330  calico.yaml

If the two MD5 values match, the file is unchanged.

You can also use sha512sum for a stronger checksum:

root@k8scludes1:~/checksum# sha512sum calico.yaml
94eece98db92232a42080e33f87e0659182e2ff9e347db38a494928c247289fcfa763a20e18ee63a84fe87f436b91e710927d138621640d6753083b8b339e8cf  calico.yaml

Save the checksum to a file:

root@k8scludes1:~/checksum# sha512sum calico.yaml > check.txt
root@k8scludes1:~/checksum# cat check.txt
94eece98db92232a42080e33f87e0659182e2ff9e347db38a494928c247289fcfa763a20e18ee63a84fe87f436b91e710927d138621640d6753083b8b339e8cf  calico.yaml

Verify the file against the stored checksum:

root@k8scludes1:~/checksum# sha512sum -c check.txt
calico.yaml: OK

Conclusion

MD5 and SHA‑512 checksums provide effective methods for confirming file integrity during download, transfer, or backup, helping maintain data consistency. While they detect accidental corruption, they do not protect confidentiality; for that, stronger encryption such as AES or RSA should be used.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxMD5checksumfile integritymd5sumSHA-512sha512sum
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.