Your Virtual Private Server Apache Web Server supports user authentication. In other words, it allows you to create password protected directories on your Virtual Private Server web site. Let's say you want to restrict access to a the following directory to those with a valid username and password.
You can configure password authentication by connecting to your server via SSH, as the administrative user for the domain you are managing, and following the steps below:
Create a file named .htaccess in your /www/htdocs/billy directory that restricts access to the directory. In our example, we will allow one user (William) to access the directory. The .htaccess file must reside in the directory it will be controlling, so we must put it in the /www/htdocs/billy directory.
You can either create the .htaccess file while connected to your server (using a file editor like pico, for example) or you can create the file on your own PC and Upload it to your Virtual Private Server. The file should contain the following text:
AuthUserFile /etc/.htpasswd AuthGroupFile /dev/null AuthName "Bill's Restaurant" AuthType Basic <Limit GET> require user William </Limit>
Use the htpasswd command to set a password for the new user.
# htpasswd -c /etc/.htpasswd William
You are free to use a different name or directory location for the password file. Just change the /etc/.htpasswd above to whatever you want.
The -c flag indicates that you are adding a user to the /etc/.htpasswd for the first time. When you add more users and passwords to the same password file, the -c flag is not necessary.
# htpasswd /home/LOGIN-NAME/etc/.htpasswd peanuts# htpasswd /home/LOGIN-NAME/etc/.htpasswd walnuts
The best place to learn about user authentication is from the source: