I want make a backup of my Home directory and I've read a good method is to use the tar tool, and I think it suits me well since all I need to do is create a .tar of every folder in the Home directory (Desktop.tar, Documents.tar, etc) and then transfer if to the External Hard Drive (EHD).

One of my concerns, though, is making sure the files that gets copied to the EHD are not corrupted in the process. So I'm was thinking to follow this procedure to verify the integrity of my data (I will use the Desktop directory as example, but it is exactly the same for every other folder):

  1. Use tar and create Desktop.tar inside my computer.
  2. Calculate md5 and sha-2 hashes for Desktop.tar.
  3. Move Desktop.tar to the EHD, which, let's say, is called backup.
  4. Calculate md5 and sha-2 hashes for backup/Desktop.tar and verify they are the same as the ones calculated in the second step.

So my questions are:

  1. Is this a good procedure to verify the data on my backup has not been corrupted in the transfer?
  2. I know the tool used to calculate the md5 hash is md5sum, but I'm not really sure what tool to use to calculate the sha-2 hash function. So should I use sha224sum, sha256sum, sha384sum or sha512sum?
  • A single SHA-256 hash of each file is guaranteed to detect accidental corruption. – Tim McLean Mar 16 '15 at 20:09

I don't think using both md5 and a short sha-2 gives you more certainty then using sha512sum alone.

Your method is in principle ok, but you can make the checking much easier by redirecting the output of sha512sum *.tar to a file sums and copy that to the destination machine as well.

Then do:

sha512sum -c sums

on the destination machine and it generates the sha512sum for each file mentioned in sums and checks it against the hash in the file

  • That looks simpler. Just one question: should I manually copy the output of the hash generator to the file or there is a command to do it? – Carl Rojas Mar 16 '15 at 20:24
  • @CarlRojas just redirect the ouput: sha512sum *.tar > sums or use tee if you want to see the output as well: sha512sum *.tar | tee sums – Anthon Mar 16 '15 at 20:39

Computing and verifying cryptographic checksums is a good method to detect changed file content, e.g. due to hard disk errors.

Like many cryptographic hash functions SHA-2 comes as a family of variants that differ in the digest size and initial values.

Since the probability to get a hash collision due to (random) bit errors is very low - even with MD5, you don't really have to 'upgrade' to SHA-2.

You would prefer SHA-2 over MD5 to protect against an attacker that deliberately tries to design a file that yields a collision. And with SHA-2 a larger digest size (i.e. 512 bits) would give you more head room against future attacks (at the cost of computation speed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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