What is the difference between Sha1sum, Sha256sum and Md5sum ? and how to check all these for some iso file? and how to create md5sum.txt file in ubuntu ?

If you look at the man page for each of those, you'll see that they say:

md5sum - compute and check MD5 message digest

sha1sum - compute and check SHA1 message digest

sha256sum - compute and check SHA256 message digest

That tells you that they all create a message digest, which is a one-way function that takes as its argument an arbitrarily sized data and returns a fixed size hash. A hash is considered impossible (within the bounds of practicality) to reverse and to find two different messages with the same hash (called a collision).

The difference between the three is the algorithm used to generate this hash.

MD5 was invented in the early 1990s and is considered flawed and obsolete by now.

SHA1 was also developed in the early 1990s. It is considered stronger than MD5, but not strong enough. Its use is currently being withdrawn from the digital signature on X.509 digital certificates.

SHA256 is the currently recommended hash function.

Unless you have a reason to use the weaker algorithms, then SHA256 is the way to go.

To create the text file, simply redirect the output to the file. For example, if you have a Ubuntu ISO image you want to hash:

 md5sum Ubuntu.iso > md5sum.txt

Of course, that works with the other variants too.

You can then (for example) distribute that file over the Internet and the recipient can check the hash again with:

md5sum Ubuntu.iso

That will print the MD5 hash which the recipient can compare with the content of the md5sum.txt file that you will have published. If they are the same, the file hasn't been tampered with.

Of course, it would be better to use sha256sum than md5sum. You'll often find a selection of these hashes published (md5sum.txt, sha1sum.txt and/or sha256sum.txt) with an ISO to allow for the fact that some systems might not have all of these utilities.

MD5, SHA-1, and SHA-256 are different hash functions (digests). They are different both in algorithm and output size.

If you check big files then you can accelerate the process by avoiding having to read the file several times. A general approach is

mkfifo md5 sha1 sha256
md5sum md5 >md5.txt &
sha1sum sha1 >sha1.txt &
sha256sum sha256 >sha256.txt &
zsh -c 'setopt MULTIOS; cat input >md5 >sha1 >sha256'

In this case it is simpler, though, because there is a program which computes several digests simultaneously:

gpg --print-mds input
  • brilliant the use of gpg, but how do I use it to compare different files? – Herman Toothrot Aug 18 '16 at 11:44
  • 1
    @user4050 You could use gpg --print-mds <file1 >digest.1; gpg --print-mds <file2 >digest.2 anf then compare digest.1 to digest.2 – Hauke Laging Jan 2 '17 at 0:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.