Learn How to Generate and Verify Files with MD5 Checksum in Linux
Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators | 4 Free Shell Scripting eBooks
A checksum is a digit which serves as a sum of correct digits in data, which can be used later to detect errors in the data during storage or transmission. MD5 (Message Digest 5) sums can be used as a checksum to verify files or strings in a Linux file system.
MD5 Sums are 128-bit character strings (numerals and letters) resulting from running the MD5 algorithm against a specific file. The MD5 algorithm is a popular hash function that generates 128-bit message digest referred to as a hash value, and when you generate one for a particular file, it is precisely unchanged on any machine no matter the number of times it is generated.
It is normally very difficult to find two distinct files that results in same strings. Therefore, you can use md5sumto check digital data integrity by determining that a file or ISO you downloaded is a bit-for-bit copy of the remote file or ISO.
In Linux, the md5sum program computes and checks MD5 hash values of a file. It is a constituent of GNU Core Utilities package, therefore comes pre-installed on most, if not all Linux distributions.
Take a look at the contents of
/etc/group
saved as groups.cvs below.
The md5sums command below will generate a hash value for the file as follows:
When you attempt to alter the contents of the file by removing the first line,
root:x:0:
and then run the command for a second time, try to observe the hash value:
You will notice that the hash value has now changed, indicating that the contents of the file where altered.
Now, put back the first line of the file,
root:x:0:
and rename it to group_file.txt and run the command below to generate its hash value again:
From the output above, the hash value is still the same even when the file has been renamed, with its original content.
Important: md5 sums only verifies/works with the file content rather than the file name.
The file groups_list.txt is a duplicate of groups.csv, so, try to generate the hash value of the files at the same time as follows.
You will see that they both have equal hash values, this is because they have the exact same content.
You can redirect the hash value(s) of a file(s) into a text file and store, share them with others. For the two files above, you can issues the command below to redirect generated hash values into a text file for later use:
To check that the files have not been modified since you created the checksum, run the next command. You should be able to view the name of each file along with “OK”.
Suggested Read: Find Top 15 Processes by Memory Usage in Linux
The
-c
or --check
option tells md5sums command to read MD5 sums from the files and check them.
Remember that after creating the checksum, you can not rename the files or else you get a “No such file or directory” error, when you try to verify the files with new names.
For instance:
Error Message
The concept also works for strings alike, in the commands below,
-n
means do not output the trailing newline:
In this guide, I showed you how to generate hash values for files, create a checksum for later verification of file integrity in Linux. Although security vulnerabilities in the MD5 algorithm have been detected, MD5 hashes still remains useful especially if you trust the party that creates them.
Verifying files is therefore an important aspect of file handling on your systems to avoid downloading, storing or sharing corrupted files. Last but not least, as usual reach us by means of the comment form below to seek any assistance, you can as well make some important suggestions to improve this post.
installing md5sum UBUNTU (apt-get install ucommon-utils)
No hay comentarios:
Publicar un comentario