LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   howto run the htpasswd command with input from file for 500 usernames !! (https://www.linuxquestions.org/questions/linux-software-2/howto-run-the-htpasswd-command-with-input-from-file-for-500-usernames-410256/)

PK2K 01-31-2006 11:34 PM

howto run the htpasswd command with input from file for 500 usernames !!
 
One of our customers required a password protected area on their webspace. We successfully completed this by creating a .htaccess and .htpasswd file in the protected folder.

Then they decided that they would need up to 500 usernames and passwords - gasp.

Inputing these with the command "htpassword -mb /var/www/secure/.htpasswd" is going to be very tedious. And whenever they add a or delete a user the changes will have to be made manually.

I was hoping that there may be a way to run the htpasswd command by gathering the usernames and passwords from a txt file or similar, but all of my "newbie" attempts have not worked.

One encouraging thing though is that if I add a user twice then their details are just updated and not duplicated which would mean if there is a way to do this then the list could just be edited and re-entered.

Thanks All in advance.

PK

thermite_1033 02-01-2006 04:36 AM

why not use a database as backend by using this module of apache:
mod_authn_dbm.so

http://httpd.apache.org/docs/2.0/mod/mod_auth_dbm.html

bathory 02-01-2006 07:45 AM

You can use a bash script like this:
Code:

#!/bin/sh

FILE=$1
FS=":"
while read line
do
        # store field 1
        NAME=$(echo $line|cut -d$FS -f1)
        # store field 2
        PASSWORD=$(echo $line|cut -d$FS -f2)
/usr/local/apache/bin/htpasswd -b .htpasswd $NAME $PASSWORD
done < $FILE

Then you have to create a file (for example named filename) containing usernames and passwords (unencrypted) one per line and using the ":" character to separate username and password (as it is in .htpasswd) and run the scipt by: ./scriptname filename. Of course you have to change the path to htpasswd in the script accordingly and "chmod +x scriptname"

PK2K 02-02-2006 02:42 AM

Newbie Registered: Mar 2005 Posts: 10 Distribution:
 
Thanks Thermite_1033

Unfortunatly the web sever is not mine and I am limited to the modifications or additions I can make to apache. But I am experimenting with your suggestion on my Debian box and will test it out

PK2K 02-02-2006 02:54 AM

Hi Bathory

That was the script I was after, it worked GREAT, I modded the path to the htpasswd command to suit debian and a test import went through without a hitch
I can easily export the users and passwords file with a ":" delimiter so this will simplify the task a lot.

I've goto learn more about bash scripting, so I'll pick apart your one as a trainer. I wonder if with some adjustments this could be used for other commands.

Thanks again, saved me hours


All times are GMT -5. The time now is 06:39 PM.