# Generating and verifying file checksums on Linux

> Create MD5 and SHA checksums on Linux and use them to check that downloaded files and backups are not corrupted.

Source: https://helpcenter.ruachost.com/developers/linux/generating-and-verifying-file-checksums-on-linux/

Learn what a checksum is, how to generate MD5 and SHA checksums, and how to verify file integrity on Linux.

## **What is a checksum?**

A **checksum** (or hash) is an alphanumeric value that uniquely represents the contents of a file. Checksums are commonly used to:

- Verify the integrity of files downloaded from external sources.
- Ensure your own files, such as backups, haven’t been corrupted or altered.

If two checksum values match, the files are identical.

## Common checksum algorithms

- ## MD5
- **SHA** (family of algorithms including SHA-1, SHA-224, SHA-256, SHA-384, SHA-512)

> **Note:** Always use the same algorithm for verification as was used to generate the checksum.

## **Generating checksums on Linux**

All **Ruachost.com** servers run Linux, which includes command line tools for generating MD5 and SHA checksums.

1. Log in via SSH.
2. At the command prompt, type one of the following, replacing `filename` with your file name:

## MD5 checksum

```
md5sum filename > md5sums.txt
```

## SHA checksum

- SHA-256:

```
sha256sum filename > sha256sums.txt
```

- SHA-512:

```
sha512sum filename > sha512sums.txt
```

The resulting `md5sums.txt` or `sha512sums.txt` file contains the checksums.

## Generating multiple checksums

- For all `.zip` files in the current directory:

```
md5sum *.zip > md5sums.txt
```

- For all files in the current directory and subdirectories:

```
find . -type f -exec md5sum {} > md5sums.txt \;
```

> Replace `md5sum` with the desired SHA command to generate SHA checksums instead.

## **Verifying checksums on Linux**

1. Log in via SSH.
2. At the command prompt, run one of the following based on your checksum file:

**MD5 verification:**

```
md5sum -c md5sums.txt
```

## SHA verification

- SHA-256:

```
sha256sum -c sha256sums.txt
```

- SHA-512:

```
sha512sum -c sha512sums.txt
```

Matching checksums display **OK**, while mismatches display **FAILED**.

**Tip:** To show only mismatched checksums, use the `--quiet` option:

```
sha512sum --quiet -c sha512sums.txt
```

## **Other operating systems**

- **Windows:** Install a checksum utility program.
- **macOS:** Use `md5` and `shasum` commands in the terminal.

## **More information**

- [MD5 Hashing Algorithm](https://en.wikipedia.org/wiki/MD5)
- [SHA Family of Hashing Algorithms](https://en.wikipedia.org/wiki/Secure_Hash_Algorithms)
