WHAT IS CHECKSUM IN LINUX?
Checksum is like a digital fingerprint of a file. In technical terms,
A checksum is a small-sized datum from a block of digital data for the purpose of detecting errors which may have been introduced during its transmission or storage.
Well, checksum is a long string of data containing various letters and numbers. You’ll generally find them while downloading files from the web, e.g. Linux distribution image, software packages etc.
Most common use of checksum is in checking if the downloaded file is corrupted.
For instance, Ubuntu MATE download page includes SHA256 checksum for every image available there. So, after you downloaded an image, you can generate SHA256 checksum for it and verify if the checksum value matches the one mentioned on the site.
If it doesn’t, that will mean your downloaded image’s integrity is compromised (maybe it was corrupted during the download process). We will use Ubuntu Mate “ubuntu-mate-16.10-desktop-amd64.iso” image file for this guide.
HOW IS CHECKSUM GENERATED?
Checksum is generated by checksum algorithm. Without going into technical details let’s say that it takes a file as input and outputs the checksum value of that file. There are various algorithms for generating checksum. Most popular checksum algorithms are:
HOW TO USE CHECKSUM TO VERIFY FILE INTEGRITY [GUI WAY]
If you are looking for graphical solution, you can use GtkHash.
GtkHash is a nifty tool for generating and verifying various checksums. It supports a wide range of checksum algorithms – including SHA, MD5 and others. Here’s a list of supported algorithms:
INSTALLING GTKHASH ON UBUNTU
For installing GtkHash on your Ubuntu system, simply run the following command:
sudo apt install gtkhash
COMMAND-LINE CHECKSUM TOOLS
Every Linux distribution comes with tools for various checksum algorithms. You can generate and verify checksum with them. The command-line checksum tools are the followings:
- MD5 checksum tool is called: md5sum
- SHA-1 checksum tool is called: sha1sum
- SHA-256 checksum tool is called: sha256sum
There are some more available, e.g.: sha224sum, sha384sum etc. All of them uses similar command formats. Let’s see an example of using sha256sum. We will use the same “ubuntu-mate-16.10-desktop-amd64.iso” image file as we used before.
GENERATING AND VERIFYING SHA256 CHECKSUM WITH SHA256SUM
First go to the directory where the .iso image is stored:
Now, for generating SHA256 checksum, enter the following command:
You will get the SHA256 checksum in your terminal window! Easy, isn’t it?
If the generated checksum matches with the one provided on the UbuntuMATE download page, that will mean – no data was changed while you downloaded the file or putting otherwise, your downloaded file is not corrupted.
The other mentioned tools work similarly.
HOW ACCURATELY DOES THIS WORK?
If you are wondering, how accurately does these checksum detects corrupted files – if you delete or change even one character from any one of the text files inside the iso image, the checksum algorithm will generate a totally different checksum value for that changed iso image. And that will definitely not match with the checksum provided on the download page.