MMNCS.COM
  • Web
    • WordPress
    • Joomla
    • Drupal
  • Tips & Tricks
    • Youtube
    • WordPress
    • Windows
    • Web
    • Twitter
    • Linux Ubuntu
    • Google
    • Facebook
    • Drupal
    • Developer
    • Designer
    • Apple
  • Tech News
    • Windows Phone
    • Servers
    • Search Engines
    • Nokia
    • Microsoft
    • iPhone
    • Google
    • Facebook
    • Browsers
    • Apple
  • Social Media
    • Youtube
    • Yahoo
    • Twitter
    • Google+
    • Facebook
  • Server
    • Web Server
      • NGINX
      • Apache Web Server
    • Ubuntu
    • Security
      • Access Control
    • Mail Server
    • Hosting
    • FTP Server
    • Firewall
    • Database
      • MySQL
    • Backup
  • SEO
    • Yahoo Search
    • Google Search
    • Google AdSense
    • Bing
  • Off-Topic
    • Weird
    • Music
    • Fun
    • Documentaries
  • Mobile
    • Windows Phone 7
    • iPhone
    • Android
  • Google
    • Google Translate
    • Google Plus
    • Google PageRank
    • Google Adwords
    • AdSense
  • Design & Dev
    • Webdevelopment
    • Version Control
      • Git Version Control
    • Programming
    • PHP
    • JavaScript
    • HTML
    • Development Environment
    • CSS

Related

  1. How To Setup a Local Development Environment for Drupal 7 Eclipse, Apache, xDebug, Git, PHP 5.3 [Windows Platform]
  • Share on Tumblr

How to password protect Apache directory for unwanted users using a htaccess file on a Linux Server

by MMNCS on April 9th, 2011, updated August 17, 2011
Apache 2 Web Server Linux Ubuntu

This guide shows how to password protect an Apache directory from unwanted users using a htaccess file on a Linux Server.

Create directory outside apache document root, so that only Apache can access password file. The password-file should be placed somewhere not accessible from the web. This is so that people cannot download the password file:

# mkdir -p /home/secure/


Add new user called user_1

# htpasswd -c /home/secure/.htpass user_1


Make sure /home/secure/.htpass file is readable by Apache web server. If Apache cannot read your password file, it will not authenticate you. You need to setup a correct permission using chown command. Usually apache use www-data user. Use the following command to find out Apache username. If you are using Debian Linux use pache2.conf, type the following command:

# grep -e ‘^User’ /etc/apache2/apache2.conf

 

Output:

www-data


Now allow apache user www-data to read our password file:

# chown www-data:www-data /home/secure/.htpass

# chmod 0660 /home/secure/.htpass


If you are using RedHat and Fedora core, type the following commands :

# grep -e ‘^User’ /etc/httpd/conf/httpd.conf

 

Output:

apache

 

Now allow apache user apache to read our password file:

# chown apache:apache /home/secure/.htpass

# chmod 0660 /home/secure/.htpass


Now our user user_1 is added but you need to configure the Apache web server to request a password and tell the server which users are allowed access. Let us assume you have directory called /var/www/site and you would like to protect it with a password.

Create the directory you what to protect /var/www/site if it does not exist:

# mkdir -p /var/www/site/user_1


Create .htaccess file using text editor:

# nano /var/www/site/user_1/.htaccess

 

Add following text:

AuthType Basic

AuthName “Restricted Access”

AuthUserFile /home/secure/.htpass

Require user user_1

 

Congrats! You can now test your site.

You may be interested in

  1. How To Setup a Local Development Environment for Drupal 7 Eclipse, Apache, xDebug, Git, PHP 5.3 [Windows Platform]

support and subscribe to the site

Follow @mmncs
Posted in Access Control, Apache Web Server, Hosting, Security, Server, Ubuntu Tags: 2011, Apache Web Server, Guide, How to password protect apache directory apache, Linux Server Setup, Online Learning, Server Setup Debian Distributions, Setup, Tutorial
« How To Setup a Local Development Environment for Drupal 7 Eclipse, Apache, xDebug, Git, PHP 5.3 [Windows Platform]
Facebook Connect Comment Box Developer API Tutorial »


Comments

You can leave a response, or trackback from your own site.
  1. 22-4-2011
    Gaige

    Terrific, that’s definitely what I was shooting for! Your article just saved me alot of looking around

    I’ll make certain to put this in good use!

    Reply
  2. 24-4-2011
    Loyd Wallett

    Valuable information and excellent website you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up

    Reply
  3. 24-4-2011
    Madaline Safko

    Stumbled into this site not later than chance but I’m unwavering inclined I clicked on that link. You unequivocally answered all the questions I’ve been on one’s deathbed to rejoinder concerning some time now. Will unquestionably up with underwrite for more of this. Acknowledgement you so much

    Reply
  4. 25-4-2011
    Ellie Lema

    Valuable information and excellent website you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up

    Reply
  5. 7-5-2011
    Darrick Brew

    Nice Blog

    Reply

Leave a Reply

Click here to cancel reply.

Trackbacks & pingbacks

  1. 10-7-2011
    How to protect Apache against DOS,DDOS or brute force attacks using mod_evasive and mod_security and mod_qos on Linux Ubuntu 11.04 | MMNCS says: [...] See also: How to password protect Apache directory for unwanted users using a htaccess file on a Linux Server [...]
  2. 26-10-2011
    How to protect Apache against DOS,DDOS or brute force attacks using mod_evasive and mod_security and mod_qos on Linux Ubuntu 11.04 - Prigad says: [...] See also: How to password protect Apache directory for unwanted users using a htaccess file on a Linux Server [...]

Search terms for this article

  • rocks password protected apache directory,
  • drupal 7 .htaccess password folder,
  • how to user dir protect linux server,
  • "www-data" user password apache2,
  • use htaccess to protect files folder drupal 7,
  • git htaccess secure,
  • htaccess password directory apache2 ubuntu,
  • ubuntu password protect folders web service api,
  • drupal 7 protect user with htaccess,
  • drupal 7 htaccess to protect download files,
  • drupal 7 password-protect page,
  • how to protect a apache development server,
  • apache password,
  • drupal access dir protect password,
  • directory password protection brute force,
  • secure drupal7 ubuntu,
  • setting up password protected directories in apache in ubuntu locally,
  • securing drupal 7 folder,
  • drupal 7 +linux +Warning: file_put_contents(temporary://,
  • .htaccess password "drupal 7",
  • apache2 htaccess brute force,
  • drupal password protect apache,
  • apache user password www-data,
  • drupal password protected folder,
  • how to password protect an image gallery apache,
  • drupal 7 directory outside drupal root,
  • ubuntu 10.04 apache2 htaccess,
  • how to make password protected apache in linux,
  • set apache password protected directories with .htaccess file windows 2.2,
  • how to password protect a .php in ubuntu 11.04,
  • Subscribe

    Find MMNCS.COM on Facebook, about guides, tutorials and learning within webdevelopment, drupal, MySQL, PHP, WordPress, SEO...
    Follow MMNCS.COM on Twitter and get the latest updates
    Follow @mmncs
    Subscribe to MMNCS.COM newsletter, about guides, tutorials and learning within webdevelopment, drupal, MySQL, PHP, WordPress, Programming, Technology, SEO...
  • The Best technology news guides tips tricks on the Internet
  • best online art gallery, paintings, illustrations, fine art photography
  • Services

    Check your Google PageRank checker optimize seo serp page rank
    Take a picture of any website, WordPress Screenshot demo
  • Latest

    Facebook Helps Breakup on One-Third of Marriages in the U.K.

    Facebook Helps Breakup on One-Third of Marriages in the U.K.

    December 30th, 2011

    Husbands and wives in the United Kingdom headed for divorce are increasingly citing Facebook in thei[...]

    Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

    Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

    December 30th, 2011

    Here's another awesome application for the Nokia Lumia 800 and other Windows Phones. Skyscanner allo[...]

    Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

    Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

    December 29th, 2011

    Rumor has it that the one thing that is notoriously missing (well, one of the things) from any Wind[...]

    Why I’m Replacing My iPhone With Nokia Lumia 800 And Why Android Is No Option

    Why I’m Replacing My iPhone With Nokia Lumia 800 And Why Android Is No Option

    December 7th, 2011

    Spoiler alert: This article is about how great the new Nokia Lumia 800 is, so if you are an iPho[...]

    Apple iPhone 4S Battery Drain Is Starting To Become A Serious Issue [iOs 5]

    Apple iPhone 4S Battery Drain Is Starting To Become A Serious Issue [iOs 5]

    November 29th, 2011

    Waiting on the next expected fix from Apple, iPhone 4S users complaining of rapid battery drain are [...]

  • musicfordriving com music for driving underground experimental electronic electronica dj rock jazz upcomming interesting music hot list hype
  • Selected

    Bill Gurley; Too Many Start-Ups Chase Too Little Cash

    Bill Gurley; Too Many Start-Ups Chase Too Little Cash

    November 14th, 2011

    Venture capitalist Bill Gurley has noticed something new this autumn: a big jump in the number of wh[...]

    The Best Programming Contest Ever Made – The AI Challenge Ants 2011 [Developer]

    The Best Programming Contest Ever Made - The AI Challenge Ants 2011 [Developer]

    October 30th, 2011

    The best programming contest ever made! Well that is what they state. The AI Challenge Ants 2011 is [...]

    Take A Picture Of Any Website [WordPress Screenshot Demo]

    Take A Picture Of Any Website [WordPress Screenshot Demo]

    October 28th, 2011

    Take a picture of any website. Just enter the website address in the form and press the button "Take[...]

    Optimize Your Time And Write Better CSS With {less} – [CSS Stylesheets]

    Optimize Your Time And Write Better CSS With {less} - [CSS Stylesheets]

    October 23rd, 2011

    If you think parts of CSS is repetitive, tedious, and … well, very boring. Have a look here. LESS [...]

    Call Your Friends For Free –  Cut The Expensive Voice And Text Plans To The Bare Minimum [Mobile Apps]

    Call Your Friends For Free - Cut The Expensive Voice And Text Plans To The Bare Minimum [Mobile Apps]

    October 14th, 2011

    After been using Viber for some time now. We highly recommend this mobile application for all smartp[...]

  • News

    Facebook Helps Breakup on One-Third of Marriages in the U.K.

    Facebook Helps Breakup on One-Third of Marriages in the U.K.

    December 30th, 2011

    Husbands and wives in the United Kingdom headed for divorce[...]

    Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

    Nokia Lumia 800 Demo of Skyscanner. Flight Deals Search for Windows Phone

    December 30th, 2011

    Here's another awesome application for the Nokia Lumia 800 and[...]

    Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

    Nokia Lumia, Samsung, HTC rumored to announce LTE Windows Phone smartphones at CES

    December 29th, 2011

    Rumor has it that the one thing that is notoriously missing[...]

  • Social Media

    Solved: Facebook XFBML Like Button Bug Creates a Vertical Scroll-Bar [Web Developer]

    Solved: Facebook XFBML Like Button Bug Creates a Vertical Scroll-Bar [Web Developer]

    September 16th, 2011

    After been doing a lot of work on the site I noticed when testing in IE8 and Firefox 3.6.x that I wa[...]

    Add a Cool Google Plus Profile Add to Circles Widget to Your Website [Google Plus]

    Add a Cool Google Plus Profile Add to Circles Widget to Your Website [Google Plus]

    August 11th, 2011

    Google Plus has created a very simple widget to embed your Google Plus profile on websites. This wid[...]

    How To Export All Your Facebook Friends To Google+ Using Yahoo Mail [Google+]

    How To Export All Your Facebook Friends To Google+ Using Yahoo Mail [Google+]

    August 8th, 2011

    Since the popular Chrome extension Facebook Friends Exporter got blocked we needed another way of ge[...]

  • Google

    Check Your Google Page Rank Here – Updated To Use The New Google PageRank Query URL

    Check Your Google Page Rank Here - Updated To Use The New Google PageRank Query URL

    October 8th, 2011

    Check PAGE RANK of Web site pages Instantly This is a free service to check Google™ page rank ins[...]

    Add a Simple Google Translate DropDown Box To Your Web Site [Tips & Tricks]

    Add a Simple Google Translate DropDown Box To Your Web Site [Tips & Tricks]

    September 6th, 2011

    Google Translate is the best free online translation service today and I often wonder why I rarely s[...]

    Google Closes Down 10 Mayor Business Areas [Tech News]

    Google Closes Down 10 Mayor Business Areas [Tech News]

    September 5th, 2011

    Google closes down 10 business areas in which the company itself calls "autumn-cleaning."The cle[...]

  • Home
  • About
  • Contact
Copyright © MMNCS.COM is a site aimed at web developers, system engineers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites. We cover Open Source recommendations, Linux Server guides, PHP, HTML, CSS, Drupal & WordPress Tutorials, Guides, Tips & Technology News.