The verification of File Integrity helps the Administrators in protecting the files and folders from unauthorized users. Usually, files are sent or received through unauthorized or insecure channels that might lead to the Original Data being altered. The Hashing Algorithm in Ubuntu helps in comparing the file with the Original File through the Hash Values.
This article discusses how you can get the md5 Hash Value of a File in Ubuntu 22.04.
How to Get md5 Hash Of A File in Ubuntu 22.04?
The md5sum or the Message Digest Algorithm 5 is a 128-bit Cryptographic Hash that helps in verifying the integrity of a file. It prints a 32-character checksum that can be verified with the original hash of the file. The MD5 Hash of a File in Ubuntu can be retrieved using Two Methods:
- Using the “md5sum” Command.
- Using the File Manager
Both methods are explained below.
Method 1: Using the “md5sum” Command to Get the MD5 Hash of a File
To get the Hash of a File using the “md5sum” command in Terminal, follow the below steps.
Navigate to the File Directory
To run the “md5sum” command, navigate to the file directory. In our case, we examine the “mysql-server” file in the “Downloads” Directory. To navigate to the Directory, we will use the “cd” command, and then the “ls” command will list all the files included in that Directory:
Once the files are listed, you can see the “mysql-server” tar file:
Run the “md5sum” Command
To verify the integrity of a file in Ubuntu, the “md5sum” Command is used along with the File Name. Once the “md5sum” command runs, it will return the hash of the file in the Terminal:
In our case, the file is a tar bundle file “mysql-server”. To get the hash of the tar file, the “md5sum” command will be executed as follows:
It will take some time to get the hash of the file and will return the hash along with the file name in the next line of Terminal:
Once you have the hash of the file by running the “md5sum” command, verify its integrity by comparing the hash value to the original hash value from the official download source. In our case, we downloaded the “mysql-server” archive file from the official “mysql” website. The archive file downloaded was for the Ubuntu Linux 22.04 Version, which you can download according to your System compatibility. The MD5 Hash value of the archive file can be seen below the Download Button.
The Hash value retrieved with the “md5sum” command is the same as the MD5 value on the official download repository which verifies and ensures the data is the same as it was initially, i.e. the file has not been changed or edited.
Method 2: Using the File Manager to Get the MD5 Hash of a File
The File Manager through the GUI can also be used to get the MD5 Hash Value of a file. Follow the steps below to get the md5 Hash of a file through the File Manager.
The “gtkhash” is a desktop utility that uses the “mhash” library for computing the checksums and message digests. The “mhash” library is an interface that provides hash algorithms. The checksum checks for errors by comparing the data derived from one source with another source in a block whereas the message digests is a widely used cryptographic one-way hashing formula. The “gtkhash” is an extension for the “nautilus” file manager and can be installed with the “apt” command:
It will ask for confirmation while adding packages to your Ubuntu System. Press “Y” to continue:
Once the “gtkhask” utility downloads, quit the “nautilus” desktop file manager with the following command:
This command will restart Nautilus as well and will enable Digests in the Properties of the file:
Go to the File Directory
Now, to get the MD5 Hash of the file. Navigate to the file directory. In our case, we have the “mysql-server” archive file in the Downloads Directory:
Right-click on the “mysql-server” archive file to open the file options menu. In the options menu, click on the “Properties” option:
The File Properties Menu appears, and you can see the “Digests” option as well which was enabled after installing the “nautilus gtkhash” utility. Click on the “Digests” Option:
In the Digests Menu, you can select the Hash Option from the List. In our case, we have to check the MD5 Hash of the file, so we will select the MD5 Option:
Once the desired options are selected, click on the “Hash” button at the Bottom of the Properties Menu which will start getting the Hash Key:
It will take some time to retrieve the Hash Value, wait for the process to complete:
When the process is completed, the Digest Column will display the Hash Values. Notice the MD5 Hash Value of the “mysql-server” file:
Apart from the md5 Hash of the File, the “SHA256” is also used for verifying the integrity of a file. To learn how to Verify File Integrity, follow the Verify Ubuntu File Guide.
To verify the file integrity, navigate to the official download web page of the file and locate the file version. In our case, we used the Official Website to download the “mysql-server” file. Each file has the MD5 Hash Value given below the Download Button option:
The Hash value retrieved using Nautilus File Manager with Digests is the same as the MD5 value on the official download repository which verifies that the file has not been changed or edited.
The MD5 Hash Value of a File can be retrieved by either using the Terminal or the GUI. The “md5sum” command gets the MD5 Hash Value of the file whereas for the GUI, the “nautilus gtkhash” has to be installed first and then the Hash value can be retrieved from the Digest Options in the File Properties. This article explains both methods in detail for getting the MD5 Hash Value of a File in Ubuntu.