Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
When you create a new user thats able to login etc etc, you also create there password for them, this obviously works with the users password being hashed irreversibly, then every time the user logs in they give their password, this is hashed again and then compared against the hash in the password file. What i'm asking is what command/function creates this hashed password that goes into the shadow file. eg you can do similar things with echo 'password'|md5sum
OR
echo 'password'|sha1sum
i'm guessing this shadow password hash is created in a similar fashion and i'd like to know what it is? So i can create my own user adding script that adds new users into a file of my own. I know to change a password you just use the passwd command but i'm trying more to be able to retrieve the output.
Hope someone knows thanks regards
ps-i've done an strace of 'passwd' but this didn't make anything to obvious in the method used
Last edited by helptonewbie; 11-27-2007 at 10:51 AM.
The makepasswd program knows how. I think it's typical these days to use md5 to do the hashing, but there is a little extra data added, so called "salt", to make it a little more difficult to brute force.
In the shadow file, if the password has field starts with $1$ it is an MD5 password. Without this I believe the crypt function is used. If you discover others (e.g. using SHA1), please post them here.
Here's how to get a hash from a password using makepasswd:
When a password is set up, md5crypt does the work of hashing the password. If md5crypt can be called from a script, then it should be possible to send it the password in plain text, and get the hash in return.
thanks guys that was interesting stuff, ron7000 no i wasn't aksing that and in a charge to try and find this out before coming to the forum i'd actually as it turns out already looked into that stuff today. bigrig, unfortunetly i seem to be unable to call the md5crypt, and matt, i also didn't have the makepassword command...makepasswd --clearfrom=- --crypt-md5 |awk '{ print $2 }'....your rite in saying it starting $1$ so it must be md5 with a salt, but there must still be some way in getting this output for myself?
cheers for replies so far
PS-i don't seem to have command pwgen either
Last edited by helptonewbie; 11-27-2007 at 03:15 PM.
hey,
i've messed around with the makepasswd command, but it doesn't create the password the same as what goes into the actual shadow file, thats what i'm trying to achieve, for instance if the password of a user was "password", i want to be able to create exactly the same hash thats already in the shadow file for that user
You have to use the --crypt-md5 option to get the right type. Most mainstream distros use the MD5 hash type (although I dare say there are a few which use others).
You can spot MD5 password hashes because they start with $1$. Here is an example which reads the password from standard input:
Hi Matt,
This would not be the command for me as i'm trying to replicate exactly or find out how for instance the password shadowing works then, if the hashed password is different every time then the only way to make it the same is to use the same salt the system does? This salt must be kept somewhere or how can the system authenticate a user on login, if the password entered by a user is changed to a hash thats different every time for whatever reason, then how can the hash i'm guessing that is compared to the hash in the shadow file for authentication work correctly?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.