LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Updating a Shadow file password through a script (https://www.linuxquestions.org/questions/linux-security-4/updating-a-shadow-file-password-through-a-script-651340/)

DRiggs 06-24-2008 01:29 PM

Updating a Shadow file password through a script
 
I have to connect into multiple Linux and UNIX boxes. My account password expires every 45 days. I would like to create a script utility to update the shadow file with the proper HASH for my new passwords monthly, but I cannot figure out how to get the proper HASH. Does anyone know how to do this?

I have seen many websites say to use "openssl passwd -1", but when I do this with my current password the result does not match what the shadow has...?

win32sux 06-24-2008 04:15 PM

Quote:

Originally Posted by DRiggs (Post 3193835)
I have seen many websites say to use "openssl passwd -1", but when I do this with my current password the result does not match what the shadow has...?

It's not supposed to match. A salt is used every time you generate, so it's normal and expected to get different hashes for the same password every time. It's all good (they will work just fine). That said, if you have a need for the strings to be exactly the same for some reason, all you have to do is specify the salt when you execute the command. So, for example:

Instead of this:
Code:

openssl passwd -1
You would use something like this:
Code:

openssl passwd -1 -salt MySalt
Remember that the salt is always stored alongside the actual hash (it's the characters between the string's second and third dollar signs). In this example output string I've put the salt in red:
Code:

$1$d9FPOhLP$W8tk2xdaXuHqMSCWDVNml.
So if I wanted to generate this hash exactly as posted (assuming I know the password, of course), I would do a:
Code:

openssl passwd -1 -salt d9FPOhLP
Hope this helps, and BTW: Welcome to LQ!!! :)


All times are GMT -5. The time now is 04:09 PM.