LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-26-2004, 10:52 AM   #1
bentman78
Member
 
Registered: Mar 2003
Location: Washington DC, USA
Distribution: Redhat
Posts: 212

Rep: Reputation: 30
how do I poassword protect a directory on a website, Apache


I know how to password protect a directory on a whole website. But what do I do if I have a site line www.site.com/private .
I want to put password protection just for the "private" sub-directory and not the rest of the site. Thanks in advanced
 
Old 04-26-2004, 11:26 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
http://httpd.apache.org/docs/howto/htaccess.html
 
Old 04-26-2004, 04:38 PM   #3
bentman78
Member
 
Registered: Mar 2003
Location: Washington DC, USA
Distribution: Redhat
Posts: 212

Original Poster
Rep: Reputation: 30
riiiiight....that still doesn't tell me how to do it for just one directory in the website. I have already looked at that document anyway. It doesn't really tell me how to do it for one directory. Can anyone give an example, I will understand it better then. In my virtual hosts section, what would I do to add basic authenication to just one directory in the website?
 
Old 04-26-2004, 04:58 PM   #4
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Well, you place the .htaccess file in the directory you want to protect.. just take note it will ask for a username and password if that one directory has any subdirectories.. but that is what your looking for, I promise
 
Old 04-26-2004, 09:37 PM   #5
tuxguy
Member
 
Registered: Mar 2004
Location: North Bay, Ontario - CANADA
Distribution: Debian
Posts: 77

Rep: Reputation: 15
1) make a .htaccess file in the dir you want to protect with the following:
Code:
AuthUserFile /path/to/dir/.htpasswd
AuthGroupFile /dev/null
AuthName "This is my server"
AuthType Basic


require user {username]
2) at the command prompt in the above dir -

htpasswd [-c] .htpasswd {username} (the -c flag creates the .htaccess file)

3) add this to your httpd.conf file and restart your server

<Directory /path/to/dir/>
AllowOverride All
</Directory>


this will give you the following output - http://kroell.homeip.net/private

Last edited by tuxguy; 04-26-2004 at 09:46 PM.
 
Old 04-27-2004, 06:51 AM   #6
bentman78
Member
 
Registered: Mar 2003
Location: Washington DC, USA
Distribution: Redhat
Posts: 212

Original Poster
Rep: Reputation: 30
Thanks guys. When I try thought I get error 1049 AuthUserFile not allowed here.

Also I have a wierd set up. I have a directory with a lot of files. So I want to password protect that directy. However the directory isn't on that server. here is the setup.

I have a web server running LAMP I'll call it server1.

I have another server with a lot of files, running NFS, server2.

I exported a directory called "files" in etc/files for example. in etc/exports.

I mounted server2:/etc/files in /mnt/files.

Then in the web directory I created a link called private to /mnt/files.
I did this ln-s /mnt/files /user/site/private

I did this because server2 has a ver large hard drive and I have a lot of files. It's running samba to, so I just drop files into it from my widows box and I am set.

It works great and I have no problems acces the stuff. I just want to password protect that directory. I also noticed I can't add the .htaccess file to the .private directory because it doesn't actually reside on that machine. so I added it to the root of the site ultimately and got this error.

I have apache 2 (Redhat distrubution)
 
Old 05-04-2004, 10:58 AM   #7
bentman78
Member
 
Registered: Mar 2003
Location: Washington DC, USA
Distribution: Redhat
Posts: 212

Original Poster
Rep: Reputation: 30
I figured this out too. I tried putting the Authuserfile and stuff in the virtual directory containers. I guess you can't do that.

You have to put the in a directory container.
 
Old 06-01-2004, 05:34 AM   #8
SuSE_fan
LQ Newbie
 
Registered: Apr 2004
Location: Provo, Utah, USA
Distribution: SuSE 9.0 Professional
Posts: 19

Rep: Reputation: 0
This may be a stupid mistake but, i did exactly as tuxguy told. this is from my httpd.conf file

<Directory /srv/www/htdocs/phps/secret>
AllowOverride all
</Directory>

and this is inside my /secret folder.

ErrorDocument 401 rejection.html
AuthUserFile /home/wasiq/.htpass
AuthGroupFile /dev/null
AuthName "Book-O-Rama"
AuthType Basic
Require user [username]

and this is from that .htpass file

user1: nnWZGCar5gVY2
user2: 4fQGZ/I/eE9kQ
user3: oAejr3UGjRLXw

now, i restarted my apache2 from runlevel editor of YaST but, still i can see the index.html page inside /secret folder...

ANY CLUE What did I do wrong? or What DIDN'T I do yet to make it work???????
 
Old 06-17-2004, 11:12 AM   #9
bentman78
Member
 
Registered: Mar 2003
Location: Washington DC, USA
Distribution: Redhat
Posts: 212

Original Poster
Rep: Reputation: 30
ErrorDocument 401 rejection.html
AuthUserFile /home/wasiq/.htpass
AuthGroupFile /dev/null
AuthName "Book-O-Rama"
AuthType Basic
Require user [username]
the above needs to be in the directory directive.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password protect a website J_K9 Programming 5 07-07-2005 08:12 AM
How Can I password protect a sub-directory of a hosted website from client PC mark001 Linux - Newbie 18 11-12-2004 02:29 PM
Need to protect a directory wayloud *BSD 1 10-13-2004 04:02 PM
how to protect images linking from other website adrianmak Linux - Software 9 10-19-2003 07:43 AM
using apache to protect a directory Syncrm Linux - Networking 0 08-31-2001 04:54 AM


All times are GMT -5. The time now is 05:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration