How to create a password-protected website?

Use "be.stat.ubc.ca"
$ssh  username@stat.ubc.ca

Here are the simplified instructions on how to make a password protected web folder for our site:

1) Create the private web folder in your web directory. This is the directory for which you want to curtail access to.

$mkdir -p  /nfs/fil-data/username/public_html/private
$mkdir -p  /nfs/fil-data/username/keys

2) Within this private web directory, create a file called

.htaccess

which contains the following text:

SSLRequireSSL
AuthType Basic
AuthName "Title of your protected folder"
AuthUserFile /nfs/fil-data/username/keys/.htpasswd
Require valid-user
ErrorDocument 403 /~username/private/
 

 

 

Notes: www.ugrad.stat.ubc.ca 
DONOT use "SSLRequireSSL" and "ErrorDocument 403 https://www.ugrad.stat.ubc.ca/~myusername/private/"
3) To create a password file with an initial user and password, use this command:

	$/usr/local/bin/htpasswd -c /nfs/fil-data/username/keys/.htpasswd user1
	... enter password for users1

To add additional users, run this command:

$/usr/local/bin/htpasswd /nfs/fil-data/username/keys/.htpasswd user2
	... enter password for users2
Note: There is no "-c" for creating second users

To delete users
$/usr/local/bin/htpasswd  -D /nfs/fil-data/username/keys/.htpasswd users

4) Make sure your files and directories have the correct permissions:

	$chmod 0711 /nfs/fil-data/username/public_html/private
	$chmod 0644 /nfs/fil-data/username/public_html/private/.htaccess
	$chmod 0711 /nfs/fil-data/username/keys
	$chmod 0644 /nfs/fil-data/username/keys/.htpasswd
 

Test the setup by using a browser and going to your private web folder:

http://www.stat.ubc.ca/~username/private/

It is important to note that this will offer some protection of your web files against unauthorized access via a web browser, but it does not protect you from StatNet users reading your files since they can go directly to your web directory via regular filesystem commands like 'cd' and 'less' and access your files.

In this case, you ought to encrypt your files (for example, by using the zip utility to created an encrypted zip archive). This is for for highly confidential information that need to be desseminated.

FAQ Category