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 Set Up Apache htpasswd Authentication in Ubuntu? F firozsh553l Follow Improve Article Tags : Linux-Unix Apache Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read Linux Commands Cheat Sheet Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W 13 min read CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi 6 min read What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac 13 min read Linux/Unix Tutorial Linux is one of the most widely used open-source operating systems. It's fast, secure, stable, and powers everything from smartphones and servers to cloud platforms and IoT devices. Linux is especially popular among developers, system administrators, and DevOps professionals.Linux is:A Unix-like OS 10 min read Like