{"id":21175,"date":"2019-06-21T23:29:46","date_gmt":"2019-06-21T20:29:46","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=21175"},"modified":"2023-06-06T02:48:07","modified_gmt":"2023-06-05T23:48:07","slug":"how-to-configure-apache-web-page-authentication","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/how-to-configure-apache-web-page-authentication\/","title":{"rendered":"Configure Apache Web Page Authentication on Ubuntu \/ Debian"},"content":{"rendered":"\n<p>How can I secure an Apache web page with Password Authentication on Ubuntu \/ Debian web server?. How to use Basic Authentication to limit access to specific web pages on Apache?. After installing and configuring your Apache web server, you may want to configure password authentication for a web page. This guide will cover how to set up a password protected directory using basic authentication.<\/p>\n\n\n\n<p>Apache web server can be installed on Ubuntu or Debian server\/workstation by running the command below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt -y install apache2<\/code><\/pre>\n\n\n\n<p>Confirm that the service is started.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">systemctl status  apache2<\/mark>\n* apache2.service - The Apache HTTP Server\n   Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)\n  Drop-In: \/lib\/systemd\/system\/apache2.service.d\n           `-apache2-systemd.conf\n   Active: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">active (running) <\/mark>since Mon 2023-06-05 23:45:36 UTC; 34s ago\n Main PID: 3797 (apache2)\n    Tasks: 55 (limit: 1110)\n   CGroup: \/system.slice\/apache2.service\n           |-3797 \/usr\/sbin\/apache2 -k start\n           |-3799 \/usr\/sbin\/apache2 -k start\n           `-3800 \/usr\/sbin\/apache2 -k start\n\nJun 05 23:45:3 ubuntu-01 systemd&#91;1]: Starting The Apache HTTP Server...\nJun 05 23:45:3 ubuntu-01 apachectl&#91;3771]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1\nJun 05 23:45:3 ubuntu-01 systemd&#91;1]: Started The Apache HTTP Server.<\/code><\/pre>\n\n\n\n<p>The following test page should be visible on the server&#8217;s IP address\/hostname.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"531\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-1024x531.png\" alt=\"\" class=\"wp-image-21195\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-1024x531.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-300x156.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-768x398.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-696x361.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-1068x554.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu-810x420.png 810w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/install-apache-debian-ubuntu.png 1367w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Apache password protected directory using basic authentication.<\/h2>\n\n\n\n<p>After installing Apache web server, install Basic Authentication packages.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt -y install apache2-utils pwauth libapache2-mod-authnz-external <\/code><\/pre>\n\n\n\n<p>Then create Apache website configuration file under <strong>\/etc\/apache2\/sites-available<\/strong> directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/etc\/apache2\/sites-available\/secure-page.conf&lt;&lt;EOF\n&lt;Directory \/var\/www\/html\/secured&gt;\n    AuthType Basic\n    AuthName \"Basic Authentication\"\n    AuthUserFile \/etc\/apache2\/.htpasswd\n    require valid-user\n&lt;\/Directory&gt;\nEOF<\/code><\/pre>\n\n\n\n<p>Add users to the Basic Authentication file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">sudo htpasswd -c \/etc\/apache2\/.htpasswd <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">webuser1<\/mark>\nNew password: \nRe-type new password: \nAdding password for user webuser1<\/code><\/pre>\n\n\n\n<p>The &#8220;<strong>-c<\/strong>&#8221; option is used to create a file during initial setup. To update file by adding other users, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">sudo htpasswd \/etc\/apache2\/.htpasswd <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">webuser2<\/mark>\nNew password: \nRe-type new password: \nAdding password for user webuser2<\/code><\/pre>\n\n\n\n<p>The file with users will have:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">cat \/etc\/apache2\/.htpasswd<\/mark>\nwebuser1:$apr1$nIxlKLgc$xGTv.J1x5wtbJqAfFPt6o1\nwebuser2:$apr1$F4OnyIyv$WImqRIR5BBopTMjqGXs\/c1<\/code><\/pre>\n\n\n\n<p>Now enable secure website.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">sudo a2ensite secure-page<\/mark>\nEnabling site secure-page.\nTo activate the new configuration, you need to run:\n  systemctl reload apache2<\/code><\/pre>\n\n\n\n<p>Create secure website directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/var\/www\/html\/secured<\/code><\/pre>\n\n\n\n<p>Add content to the directory for testing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/var\/www\/html\/secured\/index.html&lt;&lt;EOF\n&lt;html&gt;\n&lt;body&gt;\n&lt;div style=\"width: 100%; font-size: 50px; font-weight: bold; text-align: center;\"&gt;\nMy secure web page - Using Basic Auth\n&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\nEOF<\/code><\/pre>\n\n\n\n<p>Restart Apache service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2<\/code><\/pre>\n\n\n\n<p>Test access to the page.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"398\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-1024x398.png\" alt=\"\" class=\"wp-image-21256\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-1024x398.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-300x117.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-768x299.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-696x271.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-1068x416.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01-1079x420.png 1079w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-01.png 1254w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>When asked for username and password, authenticate with credentials configured earlier.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"181\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02-1024x181.png\" alt=\"\" class=\"wp-image-21259\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02-1024x181.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02-300x53.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02-768x136.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02-696x123.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02-1068x188.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2019\/06\/secure-apache-debian-ubuntu-02.png 1774w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We have confirmed basic authentication to be working for accessing a secure web page. The same procedure applies to secure existing web pages on your server.<\/p>\n\n\n\n<p><strong><em>Recommended Linux Books&nbsp; to read:<\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/5-best-computer-programming-books-for-beginners\/\">Best Linux Books for Beginners &amp; Experts<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/best-linux-kernel-programming-books\/\">Best Linux Kernel Programming Books<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/free-books-to-learn-linux-bash-scripting\/\">Best Linux Bash Scripting Books<\/a><\/li>\n<\/ul>\n\n\n\n<p>You can also check.<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"Secure LDAP Server with SSL\/TLS on Ubuntu (opens in a new tab)\" href=\"https:\/\/computingforgeeks.com\/secure-ldap-server-with-ssl-tls-on-ubuntu\/\" target=\"_blank\">Secure LDAP Server with SSL\/TLS on Ubuntu<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/computingforgeeks.com\/best-secure-backup-program\/\" target=\"_blank\">Best secure Backup Application for Linux, macOS &amp; Windows<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"How To Secure GitLab Server with SSL Certificate (opens in a new tab)\" href=\"https:\/\/computingforgeeks.com\/how-to-secure-gitlab-server-with-ssl-certificate\/\" target=\"_blank\">How To Secure GitLab Server with SSL Certificate<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"How to Set Secure Password Policy on Zimbra (opens in a new tab)\" href=\"https:\/\/computingforgeeks.com\/how-to-set-secure-password-policy-on-zimbra\/\" target=\"_blank\">How to Set Secure Password Policy on Zimbra<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can I secure an Apache web page with Password Authentication on Ubuntu \/ Debian web server?. How to use Basic Authentication to limit access to specific web pages on Apache?. After installing and configuring your Apache web server, you may want to configure password authentication for a web page. This guide will cover how &#8230; <a title=\"Configure Apache Web Page Authentication on Ubuntu \/ Debian\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/how-to-configure-apache-web-page-authentication\/\" aria-label=\"Read more about Configure Apache Web Page Authentication on Ubuntu \/ Debian\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":21256,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,26,299,50,75,81],"tags":[241,6172],"cfg_series":[],"class_list":["post-21175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-debian","category-how-to","category-linux-tutorials","category-security","category-ubuntu","tag-apache","tag-password"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/21175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=21175"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/21175\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/21256"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=21175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=21175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=21175"},{"taxonomy":"cfg_series","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/cfg_series?post=21175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}