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.

<code>root@k8scludes1:~# ls
calico.yaml</code>

Generate its MD5 checksum:

<code>root@k8scludes1:~# md5sum calico.yaml
9cc4a633f4ba45f0fd723512ec60f330  calico.yaml</code>

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

scp

):

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

On the destination machine, verify the file exists:

<code>[root@etcd2 test]# ls
calico.yaml</code>

Compute the checksum again on the destination:

<code>[root@etcd2 test]# md5sum calico.yaml
9cc4a633f4ba45f0fd723512ec60f330  calico.yaml</code>

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

You can also use

sha512sum

for a stronger checksum:

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

Save the checksum to a file:

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

Verify the file against the stored checksum:

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

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.

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

login 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.