Quote:
Originally Posted by zazzybob
This is on an ESX 3.x.x box, but you've got a few options.
The first is to use the --stdin option to passwd, e.g.
Code:
# useradd -m -d /home/foo foo
# echo "foo" | passwd --stdin foo
Changing password for user foo.
passwd: all authentication tokens updated successfully.
This would require you storing the plain text password in your script. A *much* safer option is to add a user and set the password as you normally would to a standard value, e.g.
Code:
# useradd -m -d /home/tmpuser tmpuser
# passwd tmpuser
...
Now, you can use the encrypted password for this user when creating other accounts, so that all newly created accounts have the same password as "tmpuser", e.g.
Code:
# useradd -m -d /home/newuser -p `awk -vFS=':' '$1 ~ /^tmpuser/ {print $2}' /etc/shadow` newuser
Cheers,
ZB
|
Thanks for the reply. I would have replied back sooner, but haven't gotten a chance to try it out till now. I actually like the --stdin option. The script actually won't be holding a plain text password. What I would like to do is generate a random password in my script, and pass it to --stdin.
I just have one problem. I'm really new to Vmware ESX, but I was able to find a little script that generates a password. Here it is:
Code:
MAXSIZE=8
array1=(
q w e r t y u i o p a s d f g h j k l z x c v b n m
)
MODNUM=${#array1[*]}
pwd_len=0
while [ $pwd_len -lt $MAXSIZE ]
do
index=$(($RANDOM%$MODNUM))
echo -n "${array1[$index]}"
((pwd_len++))
echo
done
As you can see, all that script does is generate the password, and then echo it out. But I've never seen where you can just use "echo" and not tell it what to echo. So what variable is my password being stored in? If it's $index, then how can I use it with --stdin?
The problem comes when I try to use it, putting this in my code:
Code:
# echo "$index" | passwd --stdin foo
because the "echo" is also printing out the password, so do you know how I can use this to my advantage?
thanks again for your help.