Wednesday, September 29, 2010

md5 On Mac OS X ~ md5sum On Linux

{Summary: Mac OS X's md5 command is analogous to Linux's md5sum. openssl can calculate many types of digests for you.}

This entry is a note to myself so that I won't repeat the same mistake again since I have done so at least twice already.

I had to transfer quite a big file from Mac OS X to a Linux server using sFTP. The session was interrupted a few times and I wanted to make sure that the file on the server was not corrupted. So I went ahead to calculate the message digest (MD5) of the file on the server and the original file on the Mac.

I typed md5sum filename on Linux and got the message digest with no problem. When I typed md5sum filename on Mac, the computer said the command was not found. So I googled for "md5sum mac os x" and the links on the first page seemed to say that md5sum should already be on my Mac.

So I typed "man md5sum" and the computer said there was no manual for the command md5sum. I then tried "man md5" and got the manual for the command md5 that would calculate the MD5 message digest just as I needed and I went ahead and used the md5 command.

After I verified that the uploaded file was not corrupted, I realized that I had done these steps before but have forgotten about it all. I looked at the files on the Linux servers and I saw a few big files that I calculated the MD5 message digests when I uploaded them. So, I must have forgotten all about the steps that led me to use md5 before and hence this note.

BTW, MD5 message digest is no longer considered secure enough for serious work and SHA1 or better digests should be used instead. To find SHA1 on Linux, use sha1sum filename. To find SHA1 on a Mac, use "openssl sha1 filename" or "openssl dgst -sha1 filename". To find SHA256 on a Mac, use "openssl dgst -sha256 filename".

If you want to calculate message digests on multiple files inside directories, you can use md5deep which calculate MD5, SHA1, SHA256, and other digests for you.

No comments: