{"id":227,"date":"2008-12-14T12:55:42","date_gmt":"2008-12-14T11:55:42","guid":{"rendered":"http:\/\/www.askthegerman.com\/?p=227"},"modified":"2023-02-13T07:36:24","modified_gmt":"2023-02-13T06:36:24","slug":"password-protect-webfolders","status":"publish","type":"post","link":"https:\/\/www.askthegerman.com\/?p=227","title":{"rendered":"Password Protect Webfolders"},"content":{"rendered":"<p>Sometimes we have to place content on our webserver we want to protect and only accessed by privileged users.<\/p>\n<p>A basic security can be established by a password restricted folder access, enforced by the Apache Webserver itself.<\/p>\n<p>This can be done by some simple instructions added to our .htaccess file:<br \/>\n(In case you haven&#8217;t already a .htaccess file, just create a new file calling it .htaccess and locating it in the folder you want to protect.)<\/p>\n<p><em>AuthType Basic<br \/>\nAuthName &#8220;Protected Area&#8221;<br \/>\nAuthUserFile FILE<br \/>\nrequire valid-user<\/em><\/p>\n<p>These commands will tell the Apache webserver that the folder in question (and all below) are now protected and it needs a valid combination of username\/password to access it.<\/p>\n<ul>\n<li><em>AuthName<\/em> is some free form text you can specify, telling the visitor what you are asking for and Apache Webserver will show in it&#8217;s dialog box.<\/li>\n<\/ul>\n<ul>\n<li><em>AuthUserFile<\/em> is the reference to the stored .htpasswd file containing all valid username\/password combinations to access the folder in question (ususally and best located out of the protected directory tree).<\/li>\n<\/ul>\n<p>Having that done we now need to create the necessary .htpasswd file which we can do interactive on our server with the command:<\/p>\n<p><em>htpasswd2 -c FILE USER<\/em><\/p>\n<p>Assuming html is your webroot, a valid example, for protecting a folder called images below our webroot and using demouser\/demopassword as user credentials, would be:<\/p>\n<p><strong>.htaccess:<\/strong><br \/>\n(Locate this file within the folder images and be aware to use an absolute path for <em>AuthUserFile, <\/em>as for <em>www.domain.com<\/em> would be wrong!)<\/p>\n<p><em>AuthUserFile \/home\/username\/html\/.htpasswd<br \/>\nAuthType Basic<br \/>\nAuthName &#8220;Login for Secure Area&#8221;<br \/>\nrequire valid-user<\/em><\/p>\n<p><strong>.htpasswd<\/strong><br \/>\n(Create a new file called .htpasswd and locate this file within the folder you&#8217;ve specified within <em>AuthUserFile <\/em>path<em>.<\/em>)<\/p>\n<p><em>demouser:$1$OHq3K5v3$pvFrGsHjWwYjpkZhc70T9. <\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we have to place content on our webserver we want to protect and only accessed by privileged users. A basic security can be established by a password restricted folder access, enforced by the Apache Webserver itself. This can be done by some simple instructions added to our .htaccess file: (In case you haven&#8217;t already [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,14,31,15,50,16],"tags":[67,209,210,37,206,208,207,205,265],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-apache","category-operatingsystem","category-tipsntricks","category-unix","category-webserver","category-windows","tag-htaccess","tag-htpasswd","tag-htpasswd2","tag-password","tag-protect","tag-username","tag-webfolder","tag-webroot","tag-webserver"],"_links":{"self":[{"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227"}],"version-history":[{"count":8,"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions"}],"predecessor-version":[{"id":358,"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions\/358"}],"wp:attachment":[{"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askthegerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}