The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SSH prompts password for non identical users vjkatsun UNIX for Advanced & Expert Users 5 06-02-2008 01:18 AM
Modify Perl script to work with txt - Permissions script joangopan Shell Programming and Scripting 1 09-12-2007 11:38 PM
Have users changed their password annemar UNIX for Dummies Questions & Answers 6 09-20-2006 04:18 AM
list the password settings for all the users irasela UNIX Desktop for Dummies Questions & Answers 3 08-17-2006 02:40 PM
Setting password restrictions for all users drathbone UNIX for Dummies Questions & Answers 2 03-03-2006 08:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-15-2007
paqman paqman is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 21
Modify users password via script?

Ok, first off, I'm working on a Vmware ESX server, which I guess is loosely based off of Red Hat 9. But I'm brand new to it (today), so be nice.

I'm trying to write a useradd script that will create some users, generate a password, and set their password to this newly generated password.

Now by hand, I can use the useradd command, and then use passwd to change their password. But if I've got to set up a couple hundred users, this is not enjoyable.

So if I can't use passwd in a script (because it requires user interaction), how can I create these users with some default password?
  #2 (permalink)  
Old 08-15-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
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
  #3 (permalink)  
Old 08-21-2007
paqman paqman is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 21
Quote:
Originally Posted by zazzybob View Post
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0