{"id":2745,"date":"2016-10-09T09:19:21","date_gmt":"2016-10-09T07:19:21","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2745"},"modified":"2020-10-05T21:11:02","modified_gmt":"2020-10-05T19:11:02","slug":"password-protecting-your-web-pages","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2745","title":{"rendered":"Password Protecting Your Web Pages"},"content":{"rendered":"<p>Want to prevent people from viewing the files in a particular web directory ?<\/p>\n<p>Here are the steps that will enable you to secure a web directory (in this example, \/var\/www\/html\/admin directory or http:\/\/yourip\/admin\/).<\/p>\n<h2>Step # 1: Make sure Apache is configured to use .htaccess file<\/h2>\n<p>You need to have AllowOverride AuthConfig directive in <strong>\/etc\/apache2\/httpd.conf<\/strong> file in order for these directives to have any effect. Look for DocumentRoot Directory entry. In this example, our DocumentRoot directory is set to \/var\/www. Therefore, my entry in <span style=\"text-decoration: underline;\"><strong>httpd.conf<\/strong><\/span> looks like as follows:<\/p>\n<pre>&lt;Directory \/var\/www&gt;\r\nOptions Indexes Includes FollowSymLinks MultiViews\r\nAllowOverride AuthConfig\r\nOrder allow,deny\r\nAllow from all\r\n&lt;\/Directory&gt;<\/pre>\n<p>Change the value from &#8220;AllowOverride None&#8221; to &#8220;<strong>AllowOverride AuthConfig<\/strong>&#8221; (or &#8220;AllowOverride All&#8221; if you want to change other, non-authorization related options).<\/p>\n<p><span style=\"text-decoration: underline;\">Save the file and restart Apache :<\/span><br \/>\n<strong>&gt; sudo service apache2 restart<\/strong><\/p>\n<p>Next Steps are to create .htccess and a .htpasswd files :<\/p>\n<ul>\n<li>From an SSH command prompt run: <strong>htpasswd -c \/etc\/apache2\/.htpasswd yourusername<\/strong> and specify the password you want (change the file location to suit). This will create a .htpasswd file like: <code><\/code><code>yourusername:me7asnd1UpLYw<\/code> (Dont put the htpasswd file inside your webroot for security reasons). -c option is to create a new<\/li>\n<\/ul>\n<ul>\n<li>In the Create Options File input, enter the name of the .htaccess file you wish to create. e.g. \/var\/www\/html\/admin\/.htaccess<\/li>\n<\/ul>\n<p>Your .htaccess file options will look like this:<\/p>\n<pre><code>\r\nAuthType Basic\r\nAuthName \"Protected Area\r\nRequire valid-user\r\nAuthUserFile \/etc\/apache2\/.htpasswd\r\n\r\n<\/code><\/pre>\n<p><strong>Protect your .htacess and .htpasswd<\/strong>. (<a href=\"http:\/\/www.askapache.com\/htaccess\/troubleshooting-apache-htaccess-authentication\/\" target=\"_blank\" rel=\"noopener noreferrer\">Read this<\/a>)<\/p>\n<p>CHMOD your .htaccess file 644 which translates to rw-r-r<\/p>\n<p>chmod your .htpasswd file 640 (rw-r&#8211;)<\/p>\n<pre>$ chmod 644 .htaccess\r\n$ chmod 640 .htpasswd<\/pre>\n<p>So in <strong>\/etc\/apache2\/sites-available<\/strong> in default websites edit with nano and add a virtual host ( <a href=\"https:\/\/wiki.apache.org\/httpd\/PasswordBasicAuth\" target=\"_blank\" rel=\"noopener noreferrer\">Read this for details<\/a>\u00a0 ) :<\/p>\n<div title=\"\/etc\/apache2\/sites-enabled\/000-default.conf\">\/etc\/apache2\/sites-enabled\/000-default.conf<\/div>\n<pre><code>&lt;VirtualHost *:80&gt;\r\n    ServerAdmin webmaster@localhost\r\n    DocumentRoot \/var\/www\/html\r\n\r\n    &lt;Directory \"\/var\/www\/html\"&gt;\r\n        AuthType Basic\r\n        AuthName \"Restricted Content\"\r\n        AuthUserFile \/etc\/apache2\/.htpasswd\r\n        Require valid-user\r\n    &lt;\/Directory&gt;\r\n&lt;\/VirtualHost&gt;\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to prevent people from viewing the files in a particular web directory ? Here are the steps that will enable you to secure a web directory (in this example, \/var\/www\/html\/admin directory or http:\/\/yourip\/admin\/).&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2843,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[94,346],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2745"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2745"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2745\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2843"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}