Results 1 to 5 of 5

Thread: Protecting A Directory

  1. #1
    Join Date
    Jan 2009
    Posts
    66

    Protecting A Directory

    I am having a small quey regarding apache server.
    I just don't know as how to enable password protection to a directory with the help of .htaccess and .htpassword files. But i am not sure as how to apply the .htpasswd file to the .htaccess file.
    Please help me regarding this query

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Protecting A Directory

    Create a file name .htaccess in the folder that you want to password protect with the content below:-

    AuthName “Password Protect Directory”
    AuthType Basic
    AuthUserFile /home/username/.htpasswd
    <Limit GET POST PUT>
    Require valid-user
    </Limit>

    - In shell type:-

    htpasswd -c /home/username/.htpasswd your_desire_username

    You will be prompt for a new password.
    - Once you enter your password, file with name .htpasswd will be created at /home/username directory and now your website folder has been password protected
    - Open your browser and try to access your password protected folder. It should now ask you to login now.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Protecting A Directory

    To password protect directory with CPanel Hosting Control Panel:-
    Login into your CPanel and click on Password Protect Directories
    Once you click on Password Protect Directories, you will see a list of directories
    Click on the directory that you wish to password protect
    Fill in a Username and Password at the bottom of the page, and click Add / modify authorized user
    Once user created successfully, just click “Go Back”
    Now, Check the Directory requires a password to access via the web
    Fill in Protected Resource Name, actually this is just the message that will show in the login window
    then, Highlight the user you just created from the Active Users list and click on Save button below the Protected Resource Name
    You are Done! The directory you just select has been protected by password.
    To ensure you directory has been password protected, launch you browser and visit the folder, if browser prompt you to login, your directory has been protected by password

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Protecting A Directory

    First, create a subdirectory in your web area. For the sake of this tutorial, I have created the "protect" directory. Set the permissions on the directory so that the server has read/execute. I do this by using the local command chgrp-www to set the group to the www group. This is the group that the server runs under at Colorado State University for the lamar, holly and www servers. I have used the -sd flag which sets "set group id" for a directory. This will then force any files you create within the protect directory to the www group, so if you ftp files to this directory they will be automatically readable by the server but not by any other user on the system. I then cd into the protect directory.

    Next you must create a .htaccess file inside the directory you want protected. You can use either the vi or pico editors on the supported systems mentioned above or ftp the file to this directory. If you are new to unix or know little about vi then I suggest you use the pico editor or ftp the .htaccess file. The command to edit with pico is "pico .htaccess". The .htaccess file should contain the following lines. The items in bold are things you will want to change depending on the location of the AuthUserFile and content of AuthName.

    The AuthName is what the user will see when they're prompted for a password - something to the effect of "Enter the username for Ric's Protected files". The AuthUserFile is location of the password file and should be not accessible with a url on the server for security reasons. This is a full unix path and the permissions should be set up like the "protect" directory using the chmod and chgrp-www commands above so the only one that can read this file is the owner and the server. To get the full path of a directory, cd to that directory and enter the command "pwd" to print the working directory path.

    Now you'll have to set up the password file. You'll need to use the htpasswd program. It is included with the Apache httpd server.

    First cd to the directory that contains the password file. In this example the password file is called .htpasswd and is in the directory /z/ric/secret/ as indicated by the AuthUserFile file entry in the .htaccess file. For every username you want to add to the password file, enter the following. (the -c is only required the first time; it indicates that you want to create the .htpasswd file).

    Again, make sure the permissions are set up like the "protect" directory using the chmod and chgrp-www commands above so the only one that can read files in the "secret" directory is the owner and the server.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Protecting A Directory

    Follow the below provided command

    cd ~ric/public_html
    mkdir protect
    chmod g+r,g+x,o-r,o-x protect
    chgrp-www -sd protect
    cd protect

    AuthUserFile /z/ric/secret/.htpasswd
    AuthGroupFile /dev/null
    AuthName "Ric's protected files"
    AuthType Basic

    <Limit GET>
    require valid-user
    </Limit>

    cd
    mkdir secret
    cd secret
    htpasswd -c .htpasswd pumpkin
    [ you're prompted for the password for pumpkin]
    [ if you have other users enter the following. Don't use the -c]
    htpasswd .htpasswd user2
    htpasswd .htpasswd user3

Similar Threads

  1. Some tips on protecting camera from rain
    By LFC18 in forum Portable Devices
    Replies: 4
    Last Post: 19-07-2013, 04:24 PM
  2. Copy protecting a pdf file
    By Gaganvihari in forum Windows Software
    Replies: 6
    Last Post: 16-08-2011, 01:29 PM
  3. Protecting access to your PC
    By monsitj in forum Networking & Security
    Replies: 2
    Last Post: 04-12-2008, 02:56 PM
  4. Protecting Documents
    By urgaffel in forum Windows Software
    Replies: 3
    Last Post: 13-10-2008, 07:39 PM
  5. Password Protecting a Folder
    By Pravda in forum Vista Help
    Replies: 7
    Last Post: 07-08-2008, 10:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,358,794.59640 seconds with 16 queries