sha1 password hash linux

Dan picture Dan · Mar 25, 2013 · Viewed 42k times · Source

What i want is to be able to get the sha1 hashed value of a particular password.

So for instance if my password was "hello" what command would i need to type into linux to get the sha1 hashed value of hello?

I tried

echo -n "hello" | sha1sum

but the value it returned did not give a value that was accepted by the database stored procedure that takes in the hashed value to verify a login(which the issue is not in this stored procedure because we use it all over the place for verfication purposes).

BASICALLY,

i just need to know a command to give a string and get back the sha1 hashed value of it

Thanks! :)

Answer

Dom picture Dom · May 24, 2016

I know this is really old but here is why it did not work and what to do about it:

When you run the

echo -n "hello" | sha1sum

as in your example you get

aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d  -

Notice the '-' in the end.

The hash in front is the correct sha1 hash for hello, but the dash messes up the hash.

In order to get only the first part you can do this:

echo -n "hello" | sha1sum | awk '{print $1}'

This will feed your output through awk and give you only the 1st column. Result: The correct sha1 for "hello"

aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

Hope this helps someone.