useradd and crypt
Michael Hipp
Michael
Tue Oct 3 19:22:49 PDT 2006
David Bandel wrote:
> On 10/3/06, Michael Hipp <Michael at hipp.com> wrote:
>> I've read numerous HOW-TOs that tell me to add users to my system like this:
>>
>> useradd -c "Fred Jones" -m -g users -p abc123 fred
>>
>> But that doesn't do what it appears to do. The '-p' option expects an
>> *encrypted* password. If I enter it like above, it puts the plaintext
>> "abc123" into /etc/shadow.
>>
>> The man page says:
>>
>> -p passwd The encrypted password, as returned by crypt(3)
>>
>> 'crypt' is a system call - not exactly something you can use from the
>> command line.
>>
>> So if I want to actually enter:
>>
>> useradd -c "Fred Jones" -m -g users -p $ENCRYPTED fred
>>
>> What do I use to actually get an encrypted password from "abc123"?
>
> apt-get install makepasswd (debian testing)
>
> (non-debian users will need to use yum and an appropriate repository).
>
> makepasswd is a great utility. I use it to generate passwds for
> students when I have to have a couple of hundred.
>
> This utility can generate random passwords, encrypt plaintext
> passwords, even provide md5 passwords if you're using md5 (you should)
> in your shadow file.
Thanks. Appears to be what I was looking for.
But in playing with it, I don't understand what it's doing. When I encrypt a
password like this:
makepasswd --crypt --string abc123
I get a different result on every run and none of them match what is in
/etc/shadow for known passwords. Also tried --crypt-md5 with similar results.
So how do you get it to match what passwd would produce so that the input to
the useradd command would be correct for /etc/shadow?
Thanks,
Michael
More information about the Linux-users
mailing list