How to Set Up Apache htpasswd Authentication in Ubuntu? Last Updated : 04 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Installing htpasswd authentication on Apache in Ubuntu is an excellent approach to fortify the web server with additional protection. We shall see the step-by-step process for that in this tutorial.PrerequisitesApache server installed.Command-line basic operations.Steps to set up Apache htpasswd authentication in UbuntuStep 1: Installing Apache UtilitiesCheck if the package for Apache utilities is installed. The htpasswd program, which is used to maintain username and password pairs, is included in this package.sudo apt updatesudo apt install apache2-utilsStep 2: Create a password FileThe credentials will be kept in a password-protected file that we will create. Place it wherever you'd like, although generally speaking, it's located at '/etc/apache2/' We're going to call the file ".htpasswd" for this tutorial.sudo htpasswd -c /etc/apache2/.htpasswd yourusernameA new password file will be created using the -c option. You will be required to input and verify your username's password. You can remove the -c argument to add more users.sudo htpasswd /etc/apache2/.htpasswd anotheruserStep 3: Configure Apache to Use the Password FileOne need to configure the apache to use this password file. This involves editing of apache configuration file or the specific virtual host file where you want to enable the authentication.open the apache configuration file or your sites virtual host file.sudo nano /etc/apache2/sites-available/000-default.confWithin the <VirtualHost> block or a specific <Directory> block, add the following configuration:<Directory "/var/www/html"> AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/apache2/.htpasswd Require valid-user</Directory>This configuration tells apache to use the basic authentication and specific '.htpasswd' file to control access to the '/var/www/html' directory.Step 4: Enable and Restart the ApacheTo apply the changes save and exit the editor.sudo systemctl restart apache2Step 5: Test the AuthenticationOpen we browser and navigate to server's address like http://localhost:8080. You will prompted to enter username and password. enter your credentials you set up with the htpasswd command.TroubleshootingCheck the following in case of any issues occurs.Ensure the .htpasswd file path is correct and accessible by the Apache process.Check the Apache error logs for any relevant error messages:sudo tail -f /var/log/apache2/error.logVerify that the mod_auth_basic module is enabled in Apache. It should be enabled by default, but you can ensure it with the following command:sudo a2enmod auth_basicConclusionSuccessfully following steps mentioned in this guide one can easily set the Apache htpasswd authentication in ubuntu. This adds a basic level of security to your web server, requiring users to provide a valid username and password before accessing restricted areas. Comment More infoAdvertise with us Next Article How to Enable HTTP/2 in Apache 2.4 on Ubuntu 20.04? F firozsh553l Follow Improve Article Tags : Linux-Unix Apache Similar Reads How to Enable & Set Up .htaccess File on Apache? The .htaccess is a simple but extremely powerful configuration file used by the web servers running on apache web server software. this .htaccess file allow to alter and change their configuration of the main configuration files without even having direct access to them. In this guide, we will look 3 min read How to install and set up Apache Virtual Hosts on Ubuntu? Every website that is published on the Internet is housed on a web server (host), which is able to handle requests for web pages made by clients using browsers like Chrome, Firefox, or Internet Explorer and is connected to the network with a public IP address. Install a web server before hosting a w 4 min read How to Set Up Apache Web Server in AWS EC2 Linux (Ubuntu) Instance? In this article, we will look into the process of setting up Apache Web Server in AWS EC2 Linux Instance.This tutorial has been done on a system running Windows 10 Home (Version 20H2).Implementation:The steps taken to complete this tutorial are being stated below:Step 1: Go to portal.aws.amazon.com 4 min read How to Install an SSL Certificate on Apache that run Ubuntu? This guide explains installing an SSL certificate on an Apache 2 server. It covers steps such as downloading and uploading the certificate file, configuring the necessary parameters on the Apache 2 server, and verifying the installation. Key parameters include the certificate file, certificate chain 4 min read How to Enable HTTP/2 in Apache 2.4 on Ubuntu 20.04? Apache 2.4 with HTTP/2 enabled on Ubuntu 20.04 will greatly enhance your web server's performance. Compared to HTTP/1.1, HTTP/2 has several benefits, such as server push, header compression, and multiplexing.PrerequisitesUbuntu 20.04Apache 2.4.17 or later (HTTP/2 functionality is available beginning 3 min read How to Install and Customize Apache on Ubuntu or Debian? One of the most dominant forces in web server software is the Apache HTTP Server, often shortened to Apache. This free and open-source project, overseen by the Apache Software Foundation, has been a major player in shaping the Internet since its launch in 1995. Installing an Apache web server on Ubu 2 min read Like