Understanding Basic Authentication

I recently had an opportunity to use Basic Authentication and Digest Authentication. Authentication is a crucial aspect of web security, ensuring that only authorized users can access specific resources. These authentication methods are widely used in …


This content originally appeared on DEV Community and was authored by Ryoichi Homma

I recently had an opportunity to use Basic Authentication and Digest Authentication. Authentication is a crucial aspect of web security, ensuring that only authorized users can access specific resources. These authentication methods are widely used in Apache server. This article will focus on Basic Authentication, especially how it works and how to implement it.

Basic Authentication

Basic Authentication is a simple authentication mechanism where the client sends credentials like username and password encoded in Base64 with each HTTP request. While Base64 encoding is not encryption, it allows the credentials to be included in a standard format. Since it lacks encryption, it is recommended to use HTTPS to secure credentials in transit.

Implementation

Follow these steps to implement Basic Authentication on the Apache server:

  • Install Apache using yum:
sudo yum install httpd -y
  • Create a protected directory:
sudo mkdir -p /var/www/html/basic

/basic can be anything.

  • Create the .htpasswd file:
sudo htpasswd -c /etc/httpd/.htpasswd username

You'll be asked to type and confirm the password.

  • Edit the Apache configuration file:
sudo vi /etc/httpd/conf/httpd.conf

Add the following inside the <Directory "/var/www/html"> section (usually from 160 lines):

<Directory "var/www/html/basic">
    AuthType Basic
    AuthName "Basic Auth"
    AuthUserFile /etc/httpd/.htpasswd
    Require user username
</Directory>
  • Create an index.html file in the protected directory:
sudo vi /var/www/html/basic/index.html

Add something you want to display when user is authorized:

You're successfully authorized.
  1. Press i to start typing in the INSERT MODE.
  2. To exit the INSERT MODE, press esc, type :wq, and press Enter.
  • Restart the Apache server:
sudo systemctl restart httpd
  • Test the authentication using curl command:
curl -L -u username:password http://xx.xx.xx.xx/basic

If you see You're successfully authorized, authentication is working correctly.


This content originally appeared on DEV Community and was authored by Ryoichi Homma


Print Share Comment Cite Upload Translate Updates
APA

Ryoichi Homma | Sciencx (2025-02-19T19:03:07+00:00) Understanding Basic Authentication. Retrieved from https://www.scien.cx/2025/02/19/understanding-basic-authentication/

MLA
" » Understanding Basic Authentication." Ryoichi Homma | Sciencx - Wednesday February 19, 2025, https://www.scien.cx/2025/02/19/understanding-basic-authentication/
HARVARD
Ryoichi Homma | Sciencx Wednesday February 19, 2025 » Understanding Basic Authentication., viewed ,<https://www.scien.cx/2025/02/19/understanding-basic-authentication/>
VANCOUVER
Ryoichi Homma | Sciencx - » Understanding Basic Authentication. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/19/understanding-basic-authentication/
CHICAGO
" » Understanding Basic Authentication." Ryoichi Homma | Sciencx - Accessed . https://www.scien.cx/2025/02/19/understanding-basic-authentication/
IEEE
" » Understanding Basic Authentication." Ryoichi Homma | Sciencx [Online]. Available: https://www.scien.cx/2025/02/19/understanding-basic-authentication/. [Accessed: ]
rf:citation
» Understanding Basic Authentication | Ryoichi Homma | Sciencx | https://www.scien.cx/2025/02/19/understanding-basic-authentication/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.