Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script question 2

Status
Not open for further replies.

stasJohn

Programmer
May 6, 2004
155
US
I'm creating a shell script to automate the creationg of web space on my server.

Basically, the first step is it creates a new user and sets the proper permissions to the user and public_html directories.

I perform the following line
Code:
useradd -G ftp,apache -m -n -p password $1

$1 is obviously a parameter. Now, when I try to access the folder via ftp, it recognized the username but password fails. I want to set the password from within the script. Am I doing it wrong?

Thanks in advance.
 
From "man useradd":

"-p passwd
The encrypted password, as returned by crypt(3). The default is to disable the account."

So, it will work, but it must be pre-encrypted. You're probably giving it plaintext.




 
The -p option expects output from the crypt function as stated in the man pages. You can however put in another line like below into your script:

echo password | passwd --stdin $1

This basically echos the word password to the passwd program as the password for user $1.


--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
thanks for the replies. The echo method worked beautifully.

It didn't work for the following though;
Code:
htpasswd -cb .passwd $1 $2
which I changed to...
Code:
echo $2 | htpasswd -cb .passwd $1 --stdin

and ideas?
 
The regular htpasswd command should work fine. It does use the plaintext version of the password.

Try "htpasswd -cb .passwd username password" from the command line. You should have a new .passwd file in the current directory.

 
Another thing you can try in your script is 'chpasswd'
Works on my AIX and Slackware systems and I'm sure it'll be on others.
Basically:

echo 'username:password' | chpasswd

or you can have a file with
username1:password
username2:password

and use chpasswd using this file



"If you always do what you've always done, you will always be where you've always been."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top