• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How To Create Password Protect Directories With Apache On Oracle Linux 9.4

  • 00:55 cat /etc/oc-release
  • 01:05 dnf install httpd -y
  • 01:23 cd /var/www/html
  • 01:36 mkdir protected && cd protected
  • 01:46 vim index.html
  • 02:29 htpasswd -c /etc/httpd/.htpasswd testuser
  • 02:59 vim /etc/httpd/conf.d/test.conf
  • 03:29 vim .htaccess
  • 03:54 systemctl restart httpd
7945

To Create Password Protect Directories With Apache On Oracle Linux 9.4

Introduction

Apache is the most widely utilized web server on Linux systems. Web servers facilitate the delivery of web pages requested by client computers. The htpasswd command enables us to create a password file for user authentication within Apache. This functionality allows us to implement password protection for directories on the Apache web server. In this video, we will provide a comprehensive overview of how to password protect directories.

Procedure

**Step 1: Check the OS version **

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.4"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.4"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:4:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.4
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.4

Step 2: Install Apache by using the below command

[root@linuxhelp ~]# dnf install httpd -y
Oracle Linux 9 BaseOS Latest (x86_64)                                                                                           21 kB/s | 4.2 kB     00:00    
Oracle Linux 9 BaseOS Latest (x86_64)                                                                                          9.1 MB/s |  45 MB     00:04    
Oracle Linux 9 Application Stream Packages (x86_64)                                                                             34 kB/s | 4.5 kB     00:00    

  Running scriptlet: httpd-2.4.62-1.0.1.el9.x86_64                                                                                                        5/10 
  Running scriptlet: httpd-2.4.57-11.0.1.el9_4.1.x86_64                                                                                                   6/10 
  Cleanup          : httpd-2.4.57-11.0.1.el9_4.1.x86_64                                                                                                   6/10 
  Running scriptlet: httpd-2.4.57-11.0.1.el9_4.1.x86_64                                                                                                   6/10 
  Cleanup          : mod_lua-2.4.57-11.0.1.el9_4.1.x86_64                                                                                                 7/10 
  Cleanup          : httpd-core-2.4.57-11.0.1.el9_4.1.x86_64                                                                                              8/10 
  Cleanup          : httpd-filesystem-2.4.57-11.0.1.el9_4.1.noarch                                                                                        9/10 
  Cleanup          : httpd-tools-2.4.57-11.0.1.el9_4.1.x86_64                                                                                            10/10 
  Running scriptlet: httpd-2.4.62-1.0.1.el9.x86_64                                                                                                       10/10 
  Running scriptlet: httpd-tools-2.4.57-11.0.1.el9_4.1.x86_64                                                                                            10/10 
  Verifying        : httpd-2.4.62-1.0.1.el9.x86_64                                                                                                        1/10 
  Verifying        : httpd-2.4.57-11.0.1.el9_4.1.x86_64                                                                                                   2/10 
  Verifying        : httpd-core-2.4.62-1.0.1.el9.x86_64                                                                                                   3/10 
  Verifying        : httpd-core-2.4.57-11.0.1.el9_4.1.x86_64                                                                                              4/10 
  Verifying        : httpd-filesystem-2.4.62-1.0.1.el9.noarch                                                                                             5/10 
  Verifying        : httpd-filesystem-2.4.57-11.0.1.el9_4.1.noarch                                                                                        6/10 
  Verifying        : httpd-tools-2.4.62-1.0.1.el9.x86_64                                                                                                  7/10 
  Verifying        : httpd-tools-2.4.57-11.0.1.el9_4.1.x86_64                                                                                             8/10 
  Verifying        : mod_lua-2.4.62-1.0.1.el9.x86_64                                                                                                      9/10 
  Verifying        : mod_lua-2.4.57-11.0.1.el9_4.1.x86_64                                                                                                10/10 

Upgraded:
  httpd-2.4.62-1.0.1.el9.x86_64      httpd-core-2.4.62-1.0.1.el9.x86_64    httpd-filesystem-2.4.62-1.0.1.el9.noarch    httpd-tools-2.4.62-1.0.1.el9.x86_64   
  mod_lua-2.4.62-1.0.1.el9.x86_64   

Complete!

Step 3: Using terminal move to the Apache Document Root by using the below command [root@linuxhelp ~]# cd /var/www/html/

Step 4: Create the "Protected" folder and go inside by using the below command [root@linuxhelp html]# mkdir protected && cd protected

Step 5: Use the vim editor to create the index.html file by using the below command [root@linuxhelp protected]# vim index.html

Step 6: Paste this sample content for the Protected area into the html file. Save the file by

<html>
<head></head>
<body>
 <h2>Protected Directory</h2>
 <b>Welcome!</b>
</body>
</html>

Step 7: Create the htpasswd file with the authentication data, then use the htpasswd command to create authentication credentials by using the below command.

[root@linuxhelp protected]# htpasswd -c /etc/httpd/.htpasswd testuser
New password: 
Re-type new password: 
Adding password for user testuser

Step 8: Configure Apache to restrict access to the directory only to users entered in the .htpasswd file. To do so, create a configuration file in the following location and paste the below content.

[root@linuxhelp protected]# vim /etc/httpd/conf.d/test.conf
<Directory "/var/www/html/protected">
 AuthType Basic
 AuthName "Protected Content"
 AuthUserFile /etc/httpd/.htpasswd
 Require valid-user
</Directory>

Step 9: Then, go to the "protected" folder and create the ".htaccess" file and paste the below content

[root@linuxhelp protected]# vim .htaccess

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user

Step 10: Restart the Apache service by using the below command [root@linuxhelp protected]# systemctl restart httpd

Step 11: To verify that the Protected area has been correctly configured snap1

Step 12: Now ask credentials for the protected directory snap2

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to create password protect directories with Apache on Oracle Linux 9.4. Your feedback is much welcome.

Tags:
jackson
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

1. What algorithm does htpasswd use?

A

modified Apache MD5 algorithm
The password will be hashed using the modified Apache MD5 algorithm. If the file does not exist, htpasswd will do nothing except return an error.

Q

2. What is the maximum password length for htpasswd?

A

255 characters
On the Windows platform, passwords hashed with htpasswd are limited to no more than 255 characters in length. Longer passwords will be truncated to 255 characters. The MD5 algorithm used by htpasswd is specific to the Apache software; passwords hashed using it will not be usable with other Web servers.

Q

3. What is the default encryption of htpasswd?

A

htpasswd encrypts passwords using either a version of MD5 modified for Apache, the system's crypt(3) routine (the default), or SHA encryption.

Q

4. Where is htpasswd stored?

A

To create the file, use the htpasswd utility that came with Apache. This will be located in the bin directory of wherever you installed Apache. If you have installed Apache from a third-party package, it may be in your execution path.

Q

5. What is the htpasswd file for Apache?

A

Create a Password File for the Apache HTTP Server

Related Tutorials in How To Create Password Protect Directories With Apache On Oracle Linux 9.4

Related Tutorials in How To Create Password Protect Directories With Apache On Oracle Linux 9.4

How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How to Completely Remove and Install Apache package on CentOS 7.6
How to Completely Remove and Install Apache package on CentOS 7.6
May 23, 2019
How to Install Pligg - Content Management System
How to Install Pligg - Content Management System
Jul 26, 2016
How to install apache jmeter on ubuntu 18.04
How to install apache jmeter on ubuntu 18.04
May 19, 2018
How to Configure HAproxy Load Balancer with Keepalived in CentOS
How to Configure HAproxy Load Balancer with Keepalived in CentOS
Nov 21, 2016
How to enable the Apache server-status on centos 7
How to enable the Apache server-status on centos 7
Jan 28, 2019
How to Create Ansible Playbook to Install Apache Server
How to Create Ansible Playbook to Install Apache Server
May 12, 2021
How to Configure Reverse Proxy with Apache in CentOS
How to Configure Reverse Proxy with Apache in CentOS
Jan 25, 2017

Related Forums in How To Create Password Protect Directories With Apache On Oracle Linux 9.4

Related Forums in How To Create Password Protect Directories With Apache On Oracle Linux 9.4

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
Apache
isaac class=
How to disable apache welcome page on Ubuntu
Dec 15, 2018
Apache
rebeccajazz class=
Apache2 : mod_proxy in opensuse
Jan 3, 2018
Apache
elijah class=
What is the difference between httpd and apache
Feb 18, 2017
Apache
logan class=
How to install Apache GUI
Feb 24, 2017
Apache
rolando class=
How to find apache user in opensuse
Sep 23, 2017
Apache
caden class=
how to use php variables in apache
May 12, 2017
Lighttpd
AadrikaAnshu class=
How to change the default port number of lighttpd web server
Jun 19, 2019

Related News in How To Create Password Protect Directories With Apache On Oracle Linux 9.4

Related News in How To Create Password Protect Directories With Apache On Oracle Linux 9.4

Attackers take advantage of Apache Struts vulnerabilities
Attackers take advantage of Apache Struts vulnerabilities
Mar 17, 2017
An Apache Web Server Bug That Grants Root Access on  Shared Web Hosts
An Apache Web Server Bug That Grants Root Access on Shared Web Hosts
Apr 10, 2019
322 new fixes released by Oracle last week
322 new fixes released by Oracle last week
Jul 30, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ganesh Konka ?
Zentya 6.1 http proxy configuration

please send link for creating zentyal 6.1 for http proxy and firewall as gateway.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.