How to Protect URLs, Files & Directories with Apache htpasswd Utility

Apache htpasswd is a tool or utility used to protect web contents such as Files, Location or URLs and Directories. Lets see about how to create basic authentication using htpasswd utility in this tutorial.


bh-ppc-banners-dynamic-760x80

What is Apache htpasswd?

[adHoriL]
Apache htpasswd is a command or utility in httpd web-server which is used to create password -text based file for authentication for users. htpasswd encrypts passwords using either a version of MD5 modified for Apache, only username is recognized in the flat file. For more reference please visit Apache official website

let see about the syntax and arguments about htpasswd,

# htpasswd --help
Usage:
htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password

htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password (default).
-d Force CRYPT encryption of the password.
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
-D Delete the specified user.

To Create new htpasswd file

For creating new authentication file with new user & password, specify the command as below, Please note -c is used for creating new htpasswd file, Dont use for second time.

# htpasswd -c /etc/httpd/conf/users NewUser1

New password:
Re-type new password:
Adding password for user NewUser1

It will prompt for password to complete. Also we can see the file users in the /etc/httpd/conf directory with one entry & encrypted password. Continue Reading

YOU MAY ALSO LIKE....

Leave a Reply

avatar
166