Hey everyone and welcome back. So previously throughout this skill what we've been learning
is how we can set up this Apache web server. Now what I want to do is I want to introduce
how we can actually use authentication so that we can ultimately protect our website.
That means that the person accessing our website would have to specify a username as well as
a password. Now you can actually implement this for many different folders within your
website. Say for example you have a forward slash blog part of your folder. You could
protect that part. But for the purposes of the examination we're just going to do a
very basic authentication implementation here. Now one thing to note that I just want
to point out is that with respect to the username that I'm talking about this actually doesn't
have to correlate with this username right here. You know the way I happen to be IPv0
on this system. The username that you can use to protect your website can be absolutely
anything you choose. So try not to confuse the two okay. So what I'm going to do to begin
is I'm going to make sure I already have a package installed. Now we already should have
this but just to make sure just do a sudo apt install and I'll say Apache to utils. If
I hit enter I will type in my password and as we can see I already have the newest version
right here. Okay so the first thing we want to do in order to be able to implement our
authentication is we want to go to one of our configuration files. So what I'm going
to do is I'll go to my Etsy directory. I'll go into my Apache directory within that and
then into sites enable. This is where we're going to have our sim links. What I'm going
to do is I'm going to look at this particular file right here. So if I open this up we can
see here we have our server admin and the document root which ultimately tells us the
directory structure where we're going to look for our HTML files to render our web page.
So the document root here what I'm going to do is I'm going to go in and I'm going to
create some tags called directory and all I'm going to do here is I'm going to specify
the directory that I want to ultimately protect so to speak. Now again you actually can add
additional things in here. You could create a directory for blog and protect that by creating
a corresponding blog directory with pages within that but for now I'm going to keep things
really quite simple. So I'll protect this directory structure here and if I tab in and
inside I'm going to say auth type is going to be basic authentication. This just means
I'll be using the username and the passwords. Now auth name here. This is really where you
can just specify some type of message here. So this name to me is a little bit confusing.
It sounds like you have to specify the username that you want to log in with. This is actually
not true. That is going to be determined by what is within the auth user file which we'll
see next. Instead this is just going to be a message that is presented to the user when
they visit the site. So I'm going to say no on authorised access and this part here the
auth user file. What I'm going to do is I'm going to specify the location of the file
that is going to house my credentials. Now this file does not actually exist yet. I'm
just going to specify where it is. So within the etsy Apache 2 directory I'm going to create
a file called my creds and it is within this file that I'll have my username and my password.
Okay. So now I will say require valid hyphen user and then to close I'm going to have to close
off my directory tag. Remember to start that off with a forward slash because we're closing the
tag and that should be us right now. So like I say our credentials are going to come within
this file right here. My creds within the etsy Apache 2 directory. Let's go and create this
file. Okay. So let me first save this and I'll exit out. So now what I'm going to do is I'm going
to use a tool called HT password. So I'll say sudo HT pass and that's pass WD dash C for create.
And now this is the file I want to create. I want to create it within the etsy Apache 2 directory
and the file is going to be called my creds. Now what I do here is I specify the username that I
want to be able to create. Now remember it doesn't have to be IPv0 in my case. It can be any username
I wish. So I'll just call this my test user and I will hit enter. Now what I want to do is to
specify the password for that user. So I'll just say password one because clearly I don't care too
much about security and I'll reconfirm password one. If I hit enter, now we can see here we actually
have added a password for that user. So if we go into this directory here, we should actually see
this file which has those credentials. So I'll CD into Apache 2 and do an LS. We can now see we
have this file called my creds. If I happen to look into this file, we can see here the my test
user with the corresponding password which is being cryptographically hashed for security. So now
our configuration file is pointing to these credentials. So in order to be able to log into
our website, we're going to have to be able to provide these credentials. So now what I want to
do is I want to restart my Apache service also to the system CTL and I will reload Apache 2. Now
if I browse to my website, watch what happens. In case I go to my virtual machine, I open up
Firefox. If I browse to this IP address, it says here, I'm trying to access this with my username
and password and we can see here the site says and this is the little message I mentioned, no
unauthorized access. You see the way auth name might be a little bit misleading. This is more
like a website message. So now what I want to do is I want to provide my credentials here. So that
is going to be my test user and the password I use was password one. So I will go in and I will
say my test user and the password is password one. So if I hit enter, that is going to authenticate
and now we actually get access to our website. Otherwise, users, whilst they might know the IP
address or the DNS resolution, they will not be able to access this website without those credentials.
So like I say, we can actually choose if we wish to just selectively protect parts of our website.
Let's maybe say that this part here was perfectly open, but you happen to have a my pictures folder
and you wanted to password protect that just like we did before within the directory tags, we can
choose whereabouts it is we want to protect. Okay, so that is us for authentication on Apache 2.
I hope this has been informative for you and I'd like to thank you for viewing.