Published on

How to Install htpasswd in Linux

Authors

What is htpasswd?

htpasswd is a CLI tool used to create and manage user authentication files and credentials for basic HTTP authentication. It uses flat-files to store usernames and passwords, which can be easily used with HTTP servers like Apache and Nginx.

How to install on Ubuntu Linux?

htpasswd is available in the apache2-utils package for Debian-based kernels. You can automatically install the utility package by using the command:

sudo apt -y update && sudo apt -y install apache2-utils

Basic Usage

To create a new file and store a new user record in it, you can use the pattern:

htpasswd -c /home/user/dir/.htpasswd NEWUSER

The user will be prompted for the password, which will be encrypted with a modified MD5 algorithm in the given file.

Other algorithms, like bcrypt can be used by using different CLI arguments in the command.

htpasswd can also display the results to the standard output rather than creating or updating a file. You can use the -n argument instead of -c for this behavior.

You can find a detailed list of arguments on the official Apache htpasswd documentation.