We can use htpasswd to keep unauthorized users from visiting a directory on your server. Most cPanel interfaces allow this feature, but if you don’t have cPanel but you have SSH login, you can use it to password protect your directory.
1. Create the password file:<br>
htpasswd -c /etc/apache2/.htpasswd username
2. Add to your Apache config or .htaccess:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
3. Restart Apache:
sudo service apache2 restart