Using .htpasswd and .htaccess to restrict access to www folders for one user using apache and BSD

1. Telnet to your shell and login

2. Create the .htpasswd file in your home directory. i.e. usr/home/username (Note: when you login to most shells this is the level you’re at)

/usr/www/bin/htpasswd -c .htpasswd user is the command that will create the password file for the username specified. You will be prompted 2x for password. (Note: in order to add more users to the .htpasswd file simply omit the –c and change username)

/usr/www/bin/htpasswd .htpasswd user2

3. Be sure to CHMOD 644 .htpasswd when done.

4. Now create the .htaccess file to restrict access to a desired folder. Typically this file shouldn't be in the same dir as the .htpasswd file. Also be sure to CHMOD 755 folder to the folder you want to restrict access to. Change to that folder.

cd folder
Pico .htaccess

AuthUserFile /usr/home/username/.htpasswd
AuthGroupFile /dev/null (go no where)
AuthName Realm (“Realm” or whatever name you like)
AuthType Basic
Require valid-user

5. Save file and then CHMOD 644 .htaccess

Using .htpasswd and .htaccess to restrict access to www folders for a group of users

1. Telnet to your shell and login

2. Create username and password for group users.

/usr/www/bin/htpasswd .htpasswd user2 (Don’t use the –c or it will create new file)

Confirm password 2x.

3. Create the .htgroup file in the same dir as the .htpasswd file.

Pico .htgroup

my-users: user1 user2 user3

4. Save file and then CHMOD 644 .htgroup

5. Now create the .htaccess file to restrict access to a folder. Typically this file shouldn't be in the same dir as the .htpasswd file. Also be sure to CHMOD 755 folder to the folder you want to restrict access to. Change to that folder.

cd folder
Pico .htaccess

AuthUserFile /usr/home/username/.htpasswd
AuthGroupFile /usr/home/username/.htgroup
AuthName Realm (“Realm” or whatever name you like)
AuthType Basic
Require valid-user

7. Save file and then CHMOD 644 .htaccess