Sub topic 2
Download and verify the installation image
This chapter assumes you can use a terminal, know what an ISO file is, and have chosen a distribution and release in the planning step. You will download an installation image, check that it is complete and unaltered, and learn what the check does and does not prove.
Why verification matters
An installation image is the root of trust for the server. Anything wrong with it carries into every file on the machine. A bad image can come from three sources:
- A corrupted download. A dropped connection or a faulty mirror can leave a file that is the wrong size or has flipped bits. The installer may fail partway through, or it may succeed and leave a damaged system.
- A tampered mirror. Mirrors are run by many volunteers and companies. A compromised one could serve a modified image.
- A wrong file. Picking the wrong architecture or release is common. A checksum will not catch this if you compare against the wrong line, so you also need to read the file name.
Verification gives you two separate guarantees. A checksum shows that your copy is identical to a reference copy. A signature shows who published that reference. They are not the same, and the difference is covered below.
Choose the right file
Distributions publish several images for each release. Check these before you download:
| Choice | What to look for | Typical mistake |
|---|---|---|
| Architecture | `amd64` or `x86_64` for most servers, `arm64` or `aarch64` for ARM | Downloading x86_64 for an ARM host |
| Image type | Netinstall (small, fetches packages during install) or full/DVD (large, mostly offline) | Using a netinstall on a machine with no network at install time |
| Edition | Server or minimal rather than a desktop live image | Installing a desktop and removing it later |
| Release | A long-term support release for production | Using a short-lived interim release on a long-lived server |
Download from the distribution's official site. Let the site pick a mirror for you, or use a mirror it lists. Prefer HTTPS. Copy the checksum file from the official site itself, not from the mirror that served the ISO. If both come from the same compromised mirror, the check proves nothing.
What a checksum is
A checksum is a fixed-length value computed from the file's bytes with a hash function. SHA-256 produces 64 hexadecimal characters. Changing one bit of the input changes the output completely. If your computed value matches the published one, the files are identical for practical purposes.
Avoid MD5 and SHA-1 for security decisions. Collisions can be produced for both. Most current distributions publish SHA-256 or SHA-512 values, so use the strongest one offered.
Vendors usually publish a text file named SHA256SUMS (Debian, Ubuntu) or CHECKSUM (Rocky, Fedora). Each line holds a hash and a file name:
3f1c0b6a9d2e4f7a8b5c1d0e9f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c *example-server-amd64.isoThe * before the name marks binary mode. It has no effect on Linux. The format is the one that sha256sum -c reads.
Verify the checksum
Put the ISO and the checksum file in the same directory, then run:
# In the directory containing the downloaded ISO and the vendor's checksum file
sha256sum -c SHA256SUMS --ignore-missingThe command reads each line of SHA256SUMS, finds the named file, computes its hash, and compares. --ignore-missing skips lines for files you did not download. A vendor's file usually lists many images, so without that option you get a failure for each missing one.
A good result looks like this:
example-server-amd64.iso: OKA failure looks like this, and the command exits with a non-zero status:
example-server-amd64.iso: FAILED
sha256sum: WARNING: 1 computed checksum did NOT matchIf you see FAILED, delete the file and download it again, ideally from a different mirror. If it fails twice, check that you have the right checksum file for the right release before suspecting an attack.
Also watch for output that says nothing matched. If --ignore-missing hides every line because the file name differs from the one in the list, the command prints a warning such as no file was verified. Do not read that as success. Rename the file to the listed name or compare the hash by hand.
Compare a single hash by hand
Some vendors show a hash on a web page instead of a file. Compute it yourself and compare:
sha256sum example-server-amd64.isoCompare the full 64 characters. Comparing only the first and last few is weak, and a visual check is easy to get wrong. Let the shell do it:
echo "3f1c0b6a9d2e4f7a8b5c1d0e9f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c example-server-amd64.iso" | sha256sum -c -Note the two spaces between the hash and the file name. That is the text-mode format, and sha256sum accepts it.
Verify the signature
A matching checksum shows that your file equals the published one. It does not show that the published checksum is genuine. An attacker who controls the page can change both. A cryptographic signature closes that gap. The vendor signs the checksum file with a private key, and you check it with the public key.
Many distributions provide a signature file next to the checksums, such as SHA256SUMS.gpg or SHA256SUMS.sign. The general steps are:
- Obtain the vendor's public signing key. Get its fingerprint from an independent, trusted source, such as the vendor's documentation over HTTPS.
- Import the key into your keyring.
- Verify the signature on the checksum file.
- Verify the ISO against the now-trusted checksum file.
With GnuPG the signature step looks like this:
gpg --import vendor-signing-key.asc
gpg --fingerprint
gpg --verify SHA256SUMS.gpg SHA256SUMSRead the output carefully. You want Good signature from with the vendor's name, and the key fingerprint must match the one you got from the independent source. A warning that the key is not certified is normal for a key you imported yourself. It means you have not signed it, not that it is bad. A line beginning BAD signature means stop.
The exact file names and key location differ per distribution, so follow the vendor's verification page. Some vendors, such as Fedora and Rocky, sign the checksum file inline, and gpg --verify CHECKSUM works on it directly.
The verification flow
Common errors
- File name mismatch. The checksum file lists
ubuntu-24.04-live-server-amd64.iso, but your browser savedubuntu-24.04-live-server-amd64 (1).iso. The tool cannot find the file. Rename it. - Truncated download. The file size is smaller than the size on the download page. Use
ls -lto compare. Resume withwget -cor download again. - Checksum file for a different release. A point release changes the ISO, so an old
SHA256SUMSfails against a new file. Download both on the same day from the same release directory. - Verifying after writing to USB. Checksum the ISO file, not the USB device. If you must check the written media, read back exactly the ISO's byte length, because the device is larger than the image.
- Trusting HTTP. Over plain HTTP, an attacker on the network path can alter both the file and the checksum. Use HTTPS, and use the signature when it is offered.
Download from the command line
On a headless host or when you need resumable transfers, fetch the files with curl or wget, then verify as above:
curl -fLO https://example.org/releases/example-server-amd64.iso
curl -fLO https://example.org/releases/SHA256SUMS
curl -fLO https://example.org/releases/SHA256SUMS.gpg
sha256sum -c SHA256SUMS --ignore-missing-f makes curl fail on HTTP errors instead of saving an error page as the ISO. -L follows redirects, which mirror networks use. -O keeps the remote file name.
Exercise
You downloaded example-server-amd64.iso and SHA256SUMS from the same mirror. sha256sum -c SHA256SUMS --ignore-missing prints example-server-amd64.iso: OK. Name one thing this result does not prove, and one step that would close the gap.
Show answer
It does not prove the checksum file is genuine, because a compromised mirror could have altered both files. Verify the signature on SHA256SUMS with the vendor's public key, after confirming the key fingerprint from an independent trusted source, or get the checksum from the vendor's official HTTPS site instead of the mirror.
Exercise
sha256sum -c SHA256SUMS --ignore-missing prints only a warning that no file was verified, and no OK line. What is the most likely cause, and how do you fix it?
Show answer
The ISO's file name does not match any name listed in SHA256SUMS, for example because the browser added (1) or you downloaded a different file. Rename the file to the exact listed name, or compute its hash with sha256sum and compare it with the published value.