{"id":13603,"date":"2019-04-03T11:35:36","date_gmt":"2019-04-03T11:35:36","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13603"},"modified":"2019-04-03T11:35:36","modified_gmt":"2019-04-03T11:35:36","slug":"learn-how-to-generate-and-verify-files-with-md5-checksum-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/learn-how-to-generate-and-verify-files-with-md5-checksum-in-linux\/","title":{"rendered":"Learn How to Generate and Verify Files with MD5 Checksum in Linux"},"content":{"rendered":"<p>A\u00a0<strong>checksum<\/strong>\u00a0is 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.\u00a0<strong>MD5<\/strong>\u00a0(<strong>Message Digest 5<\/strong>) sums can be used as a checksum to\u00a0<a href=\"https:\/\/www.tecmint.com\/generate-verify-check-files-md5-checksum-linux\/\" target=\"_blank\" rel=\"noopener\">verify files or strings in a Linux file system<\/a>.<\/p>\n<p><strong>MD5 Sums<\/strong>\u00a0are 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.<\/p>\n<p>It is normally very difficult to find two distinct files that results in same strings. Therefore, you can use\u00a0<strong>md5sum<\/strong>to 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.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/progress-monitor-check-progress-of-linux-commands\/\" target=\"_blank\" rel=\"noopener\">Progress \u2013 Monitor Progress for (cp, mv, dd, tar, etc.) Commands in Linux<\/a><\/p>\n<p>In Linux, the\u00a0<strong>md5sum<\/strong>\u00a0program 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.<\/p>\n<p>Take a look at the contents of\u00a0<code>\/etc\/group<\/code>\u00a0saved as\u00a0<strong>groups.cvs<\/strong>\u00a0below.<\/p>\n<pre>root:x:0:\r\ndaemon:x:1:\r\nbin:x:2:\r\nsys:x:3:\r\nadm:x:4:syslog,aaronkilik\r\ntty:x:5:\r\ndisk:x:6:\r\nlp:x:7:\r\nmail:x:8:\r\nnews:x:9:\r\nuucp:x:10:\r\nman:x:12:\r\nproxy:x:13:\r\nkmem:x:15:\r\ndialout:x:20:\r\nfax:x:21:\r\nvoice:x:22:\r\ncdrom:x:24:aaronkilik\r\nfloppy:x:25:\r\ntape:x:26:\r\nsudo:x:27:aaronkilik\r\naudio:x:29:pulse\r\ndip:x:30:aaronkilik\r\n<\/pre>\n<p>The\u00a0<strong>md5sums<\/strong>\u00a0command below will generate a hash value for the file as follows:<\/p>\n<pre><strong>$ md5sum groups.csv<\/strong>\r\n\r\n<strong>bc527343c7ffc103111f3a694b004e2f<\/strong>  groups.csv\r\n<\/pre>\n<p>When you attempt to alter the contents of the file by removing the first line,\u00a0<code>root:x:0:<\/code>\u00a0and then run the command for a second time, try to observe the hash value:<\/p>\n<pre><strong>$ md5sum groups.csv<\/strong>\r\n\r\n<strong>46798b5cfca45c46a84b7419f8b74735<\/strong>  groups.csv\r\n<\/pre>\n<p>You will notice that the hash value has now changed, indicating that the contents of the file where altered.<\/p>\n<p>Now, put back the first line of the file,\u00a0<code>root:x:0:<\/code>\u00a0and rename it to\u00a0<strong>group_file.txt<\/strong>\u00a0and run the command below to generate its hash value again:<\/p>\n<pre><strong>$ md5sum groups_list.txt<\/strong>\r\n\r\n<strong>bc527343c7ffc103111f3a694b004e2f<\/strong>  groups_list.txt\r\n<\/pre>\n<p>From the output above, the hash value is still the same even when the file has been renamed, with its original content.<\/p>\n<p><strong>Important<\/strong>:\u00a0<strong>md5 sums<\/strong>\u00a0only verifies\/works with the file content rather than the file name.<\/p>\n<p>The file\u00a0<strong>groups_list.txt<\/strong>\u00a0is a duplicate of\u00a0<strong>groups.csv<\/strong>, so, try to generate the hash value of the files at the same time as follows.<\/p>\n<p>You will see that they both have equal hash values, this is because they have the exact same content.<\/p>\n<pre><strong>$ md5sum groups_list.txt  groups.csv<\/strong> \r\n\r\n<strong>bc527343c7ffc103111f3a694b004e2f<\/strong>  groups_list.txt\r\n<strong>bc527343c7ffc103111f3a694b004e2f<\/strong>  groups.csv\r\n<\/pre>\n<p>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:<\/p>\n<pre><strong>$ md5sum groups_list.txt  groups.csv &gt; myfiles.md5<\/strong>\r\n<\/pre>\n<p>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\u00a0<strong>\u201cOK\u201d<\/strong>.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/find-processes-by-memory-usage-top-batch-mode\/\" target=\"_blank\" rel=\"noopener\">Find Top 15 Processes by Memory Usage in Linux<\/a><\/p>\n<p>The\u00a0<code>-c<\/code>\u00a0or\u00a0<code>--check<\/code>\u00a0option tells md5sums command to read MD5 sums from the files and check them.<\/p>\n<pre>$ md5sum -c myfiles.md5\r\n\r\n<strong>groups_list.txt: OK\r\ngroups.csv: OK<\/strong>\r\n<\/pre>\n<p>Remember that after creating the checksum, you can not rename the files or else you get a \u201c<strong>No such file or directory<\/strong>\u201d error, when you try to verify the files with new names.<\/p>\n<p>For instance:<\/p>\n<pre><strong>$ mv groups_list.txt new.txt<\/strong>\r\n<strong>$ mv groups.csv file.txt<\/strong>\r\n<strong>$ md5sum -c  myfiles.md5<\/strong>\r\n<\/pre>\n<div class=\"code-label\">Error Message<\/div>\n<pre>md5sum: groups_list.txt: No such file or directory\r\ngroups_list.txt: FAILED open or read\r\nmd5sum: groups.csv: No such file or directory\r\ngroups.csv: FAILED open or read\r\nmd5sum: WARNING: 2 listed files could not be read\r\n<\/pre>\n<p>The concept also works for strings alike, in the commands below,\u00a0<code>-n<\/code>\u00a0means do not output the trailing newline:<\/p>\n<pre><strong>$ echo -n \"Tecmint How-Tos\" | md5sum -<\/strong> \r\n\r\n<strong>afc7cb02baab440a6e64de1a5b0d0f1b  -<\/strong>\r\n<\/pre>\n<pre><strong>$ echo -n \"Tecmint How-To\" | md5sum -<\/strong> \r\n\r\n<strong>65136cb527bff5ed8615bd1959b0a248  -<\/strong>\r\n<\/pre>\n<p>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.<\/p>\n<p>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.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/generate-verify-check-files-md5-checksum-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A\u00a0checksum\u00a0is 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.\u00a0MD5\u00a0(Message Digest 5) sums can be used as a checksum to\u00a0verify files or strings in a Linux file system. MD5 Sums\u00a0are 128-bit character strings (numerals and letters) resulting &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/learn-how-to-generate-and-verify-files-with-md5-checksum-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Learn How to Generate and Verify Files with MD5 Checksum in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13603","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13603"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13603\/revisions"}],"predecessor-version":[{"id":13604,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13603\/revisions\/13604"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}