Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate generation of htpasswd from command line without typing password?

Tags:

I am trying to automate creating a password from the command line. I have tried the below but it still keeps asking for the password.

echo "test101" | htpasswd -c ~/temp/password admin 

How to generate automate htpasswd from command line without typing password?

like image 255
Tampa Avatar asked Apr 15 '12 17:04

Tampa


People also ask

How do I generate a password for htpasswd?

Use the htpasswd generator to create passwords for htpasswd files. Just enter username and password and an entry for a htpasswd file is generated. You can use the htaccces Authentication generator to create a htaccess file that will password protect your site or a directory.

What is htpasswd command?

htpasswd is used to create and update the flat-files used to store usernames and password for basic authentication of HTTP users.

Where is htpasswd stored?

htpasswd file in /var/www . You can place the . htpasswd pretty much anywhere other than your web folder.


2 Answers

Why not just use:

htpasswd -b -c ~/temp/password admin test101 
like image 84
GavinCattell Avatar answered Oct 08 '22 19:10

GavinCattell


If you don't have htpasswd installed (for example when using nginx) you can generate a password with openssl.

printf "USER:$(openssl passwd -crypt PASSWORD)\n" >> .htpasswd 
like image 32
elim Avatar answered Oct 08 '22 21:10

elim