Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-31-2006, 11:34 PM   #1
LQ Newbie
Registered: Mar 2005
Posts: 14

Rep: Reputation: 0
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.

Old 02-01-2006, 04:36 AM   #2
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
why not use a database as backend by using this module of apache:
Old 02-01-2006, 07:45 AM   #3
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,819

Rep: Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591Reputation: 1591
You can use a bash script like this:

while read line
        # 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"

Last edited by bathory; 02-01-2006 at 07:49 AM.
Old 02-02-2006, 02:42 AM   #4
LQ Newbie
Registered: Mar 2005
Posts: 14

Original Poster
Rep: Reputation: 0
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
Old 02-02-2006, 02:54 AM   #5
LQ Newbie
Registered: Mar 2005
Posts: 14

Original Poster
Rep: Reputation: 0
Thumbs up

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Usernames/password command? wardialer Linux - Security 7 02-26-2005 12:15 AM
howto run a java.jar file in FC2-3 mickeyboa Fedora 1 02-11-2005 01:01 PM
how to use the output of a file for input of a command sneak Linux - General 2 05-12-2004 09:21 AM
run java programs from the command line...howto? rmanocha Programming 3 03-06-2004 02:50 AM
input file to htpasswd igcsteve Linux - Newbie 4 06-05-2003 12:54 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:22 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration