5 comments

[ 4.4 ms ] story [ 18.4 ms ] thread
This article cites using `pwcrypt` to return the password, and that doesn't seem to be easily available (at least, not in Ubuntu 10.04.) Is there an alternative command-line interface to the crypt() function?
yes there is:

perl -e 'print crypt("password", "salt")

so you would do something like:

useradd -d / -g users -p $(perl -e'print crypt("foo", "aa")') -M -N foo

working example for the site:

cat newusers | while read u p n

do

useradd --comment "$n" --password $(python -c 'import crypt; import os; print crypt.crypt(os.environ.get("p", ""),"salt")') --create-home $u

done

Couldn't get it work with perl:)

Correct Version:

cat newusers | while read u p n

do

export p

useradd --comment "$n" --password $(python -c 'import crypt; import os; print crypt.crypt(os.environ.get("p", ""),"salt")') --create-home $u

done

Hey, this worked! Thank you so much :)