# Basic authentication

To protect some directory with basic authentication we have to edit the virtual host file and add some configurations like this:

```shell
<Directory /home/someuser/somesite/public_html>
    AuthType Basic
    AuthName "Authentication Required"
    AuthUserFile "/home/someuser/.htpasswd"
    Require valid-user
</Directory>
```

 Then we have to create the user credentials file (AuthUserFile) with ***htpasswd*** command, in this example we will be using the file "/home/someuser/.htpasswd"

Using bcrypt

```shell
htpasswd -nbB USERNAME PASSWORD
```

Using MD5

```shell
htpasswd -nbm USERNAME PASSWORD
```

 Using SHA1

```shell
htpasswd -nbs USERNAME PASSWORD
```

Using CRYPT

```shell
htpasswd -nbd USERNAME PASSWORD
```

[https://wiki.apache.org/httpd/PasswordBasicAuth](https://wiki.apache.org/httpd/PasswordBasicAuth "https://wiki.apache.org/httpd/PasswordBasicAuth")

[https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-apache-on-ubuntu-14-04](https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-apache-on-ubuntu-14-04 "https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-apache-on-ubuntu-14-04")

[https://httpd.apache.org/docs/2.4/misc/password\_encryptions.html](https://httpd.apache.org/docs/2.4/misc/password_encryptions.html "https://httpd.apache.org/docs/2.4/misc/password_encryptions.html")