Originally posted by benjalien
I'm looking to find out how I could crypt a password in the correct format for the shadow file.
I mean I'm triing to manually chage passwords without using the specific passwd command, so I need to crypt the password by myself and go write it directly in the shadow file.
Can anyone please help me with that?
I actually don't know of a program that will do that... but here is some code I whipped up that will.
This is very simple and you'd need to add input functions but this is how it works.
to compile this to a program save the above code to a file.. lets call it blah.c, then compile it thus:
gcc -o blah blah.c -lcrypt
then execute it with ./blah
What it does is takes the password "pass1234" and uses the salt "12345" and poops out something that is useable in your shadow file. For this example when I ran it the result was:
I tested this (just to be sure) by making a test user then changed the shadow file with the above. I was able to logon using the password "pass1234".. so it works.
To make this a useful program you'd need to add code that asks for the salt and the password. I won't go into what a salt is and why you need one. Much smarter people than me have already descibed this and I would only be parroting their words.
I'm sure perl has something for this as well but the c code was the first thing I thought of.
edit: For more info check out 'man crypt'