When I go online and calculate a hash from a string on some generator website, no matter the algorithm or the website, it is always a different output than if I do echo "password" | sha256sum (or insert *sum there for corresponding algorithm). What is the difference between the two?


Very possibly, the newline.

Try this instead:

$ echo -n "password" | sha256sum

The -n argument to echo tells it not to print a newline.

As you can see, this changes the hash:

$ echo "password" | sha256sum
6b3a55e0261b0304143f805a24924d0c1c44524821305f31d9277843b8a10f4e  -
$ echo -n "password" | sha256sum
5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8  -
  • 3
    This. But please note some versions of echo don't support -n and would print it literally. Check the behavior of yours first. If you need a portable way, use printf(1): `printf "%s" "password"' – Ángel Oct 3 '19 at 1:07

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.