How to Get Around the md5sum Carriage Return Issue

April 20, 2009

There’s an issue with md5sum where it returns unexpected results due to the fact that appends a carriage return to what you’re trying to get a sum of.

So if you try and get a sum of "password" by summing a file with the word "password" as the only line in the file, you won’t actually be summing "password", but rather "password[^M]", which obviously won’t be the same.

The Fix

So a quick fix for this is to use echo to feed md5sum with the -n option, which removes the trailing carriage return:

echo -n "password" | md5sum

supporting = loving

Since 1999 I've been creating ad-free technical tutorials and essays here. It's a one-person effort that's also my life and livelihood. If it makes your day more livable in any way, please consider supporting the work with a monthly or one-time donation. Your support means a lot to me, and makes all the difference. 🫶🏼