Connecting our Key in our Server User
At this stage if you where following our windows or mac videos you now have a public and private keys and you have uploaded your public key onto the server. It's time for us to connect this new key pair with our server so it can be used as the main way we validate the user and to log in.
Video Transcript
00:00Now, isn't this nice?
00:01Both Windows and Mac users unite under the same tutorial.
00:06It's just heartwarming.
00:07Okay, so you're inside of your terminal,
00:10you're inside of your PUTI,
00:12and you already moved your file.
00:15I'm just gonna do your LS, which is a bureau.
00:18It basically shows the files
00:19that are inside of that folder.
00:22You'll see that we created a file called ID underscore RSA.
00:27What I really want this file to be
00:29is in a different location.
00:31So to do that, I want to create a new folder,
00:33and I'm gonna create a new folder by typing mkdir,
00:36and then I'm gonna put a space.
00:37I'm gonna type the name of the folder I want to create,
00:40which is gonna be .ssh.
00:43So I've created the folder .ssh.
00:46Now, if I do an LS again, and I try to search for the file,
00:49you'll see the file doesn't come back.
00:51It's non-existent.
00:53And the reason why the file is not coming back
00:55is because every file, every folder file you create,
00:59that starts with a dot, automatically is hidden on a Linux.
01:02That is true.
01:03It's on a Mac, by the way, if you're a Mac user.
01:05If you want to see that file,
01:07you need to tell your directory, your LS command,
01:10that you want to see the hidden files as well.
01:12And to do that, we write minus AS.
01:16And when we do that,
01:16you'll see that now we're gonna get
01:18all the different files there,
01:19and you can see there's quite a few hidden files
01:21inside of our folder.
01:23And among them, here's our folder, .ssh.
01:27Now, if we're already talking about searches,
01:28I want to talk about one more thing.
01:30So not only could you do a search
01:31to show you the hidden files,
01:33you could also ask to get information,
01:35the list to get the files in a list,
01:38which will give you more information on every file.
01:40So to do that, I add minus L.
01:42Now I could have done minus L alone or minus AS alone.
01:45I didn't have to do both.
01:47If I would only do the L without the AS,
01:49I would only get the publicly available file.
01:51Now, what I want you to notice is that
01:54you have your two lines here.
01:55And these are the two lines I want to focus on for now.
01:58One line says, who created the file?
02:01More or less, who owns the file?
02:03Who is the file associated to?
02:06And to what group is it associated to, give or take?
02:10Now, because this is a security file,
02:12we don't want to let a group into this file.
02:14This is a security that only the specific user
02:17could log into, then it's fine.
02:18We have our user that it's demo demo.
02:20Now, you don't have to worry about it
02:22because when you create a file,
02:23it's by default gonna be owned by,
02:27and in the group of that specific user only.
02:30And you could change that.
02:31Well, we don't need to talk about it
02:33because you wouldn't want to move a file
02:37from a different directory of a different user
02:39into this directory.
02:40At this stage, you'd want to create the file yourself
02:42or upload it yourself, and that would make sure
02:44that the file would be associated to the user demo,
02:47just as we did in this case.
02:49But we'll talk about that and maybe in a future video,
02:51but for now, I want to talk about permissions.
02:54And even before I do that,
02:55I really want to move the file ID underscore RSA dot pub
03:00into the dot SSH folder.
03:02So to do that, I'm gonna use the move command,
03:04and the move command expects a couple of parameters.
03:07The first thing that the move command expects
03:09is the file name itself, which is the ID RSA dot pub,
03:14and then it asks me what do I want to call it
03:16or to where do I want to move it?
03:18So I want to move it to it.
03:19I'm gonna start with a dot,
03:20which dot means in the current folder that I'm in.
03:23Now, the current folder that I'm in is in my home directory,
03:26and you see this kind of like squiggly line here
03:28that I highlighted, that defines the home.
03:31Now, if I wanted to, I could have also just said,
03:33just put here that squiggly line instead,
03:35because that would take me to the home as well.
03:37So either or, or dot, or squiggly line
03:39if you're in the home directory, it's the same thing.
03:43And then I want to type in the SSH folder,
03:45and I want to create a file called authorized underscore keys.
03:51And call it under authorized keys.
03:54I'm gonna click on save.
03:55Once I enter, it's gonna move that file.
03:57So if I try to do a list again,
04:00you'll see that my file is not there anymore
04:02because it actually is inside of my SSH folder.
04:06And it's now called authorized underscore keys.
04:09So now that we got the files into the right place,
04:12I want to make sure that the permissions of these folders
04:15are the permissions I want them to be.
04:17So let's talk a bit about permission
04:19So let's talk a bit about permissions,
04:20and let me just clear things up here a bit.
04:23In, in, in, in, in, in, in, in Linux,
04:26there are basically the way we define a file.
04:29Permissions is dependent on three things.
04:31We looked at file permissions,
04:32we looked at user level access already before,
04:35and we said there's the user level.
04:37We said there's the group level.
04:40And intuitively, there's whoever's not in that group.
04:43In other words, more or less is saying,
04:47if you are, if you live in this house,
04:50you have permissions to come in and out
04:51whenever you want to.
04:53If you're a guest in this house,
04:54well, you have a right to one, two, three, but not four.
04:58And if we don't even know you,
04:59then you only have a right to buzz the door, Bill.
05:02Really.
05:03Now there's three different things.
05:04What could you do with files?
05:05What could you do with folders on any computer?
05:07When you think about it, there's basically three things.
05:10One is to execute the file.
05:11So there's an, if there's an executable file there,
05:14just by calling it,
05:15it could run some sort of a script, right?
05:18So we could decide,
05:19should we let him run that script or not?
05:20That's question number one.
05:22Question number two,
05:23should we let them see the source files of that file?
05:26Could we give them access to see such?
05:28Maybe there's passwords inside there.
05:29Maybe we don't want users to be able to see
05:32stuff inside there.
05:34And the third is,
05:35do we want to let them edit it?
05:37Now the ways that we define that,
05:39and basically it's very, very simple.
05:41One means they,
05:43well, let me track back here for a second.
05:46One means you could execute.
05:48Basically it means one is you could call this file.
05:52You can't see what's inside of it.
05:53You can't edit it.
05:55You could call it.
05:56And then it will execute whatever it needs to execute.
05:59Option number two is two.
06:01And two means you could write into it.
06:04Basically meaning that you could change something in it,
06:06but that does not mean that you could look into it.
06:08Maybe it's a directory of passwords
06:10and maybe you could write into it
06:12another password.
06:13Or maybe you could write in a log
06:15so to update the file,
06:17that's something that you were doing.
06:18But you cannot read what's inside of that file
06:20because it's a one way street.
06:22So that's two.
06:24Now four on the other hand,
06:25there's only three values.
06:27One, two, or four.
06:28And we're going to see why there is no,
06:30why it's these numbers and not other numbers.
06:32Now four means that you could read the file
06:35and only read.
06:36Now what would happen if I want to let a user
06:39both execute and write a file?
06:42If I want to let a user execute and write the file,
06:44I'll take the value one plus two,
06:47and that equals three.
06:48So then the user could execute or write.
06:51Now if I put the value,
06:52if I wanted the user to be able to do everything,
06:54which means I wanted to be able to re execute,
06:56I wanted to be able to write,
06:58and I want them to be able to read,
07:00I would combine all those three together
07:02and that would be seven.
07:03And that's basically how you define the combinations.
07:05So you have like a limited amount of combinations.
07:08All these together.
07:09So seven would mean this user could execute,
07:12they could write, they could read.
07:13Well on the other hand,
07:14if we set it to be the value of let's say six,
07:16six would mean you could read it,
07:18you could write it,
07:19but you can't execute it.
07:21All right, all you could do is read or write,
07:22but you can't run any script there.
07:25All right, so that's basically the different,
07:27the structures of defining access levels.
07:33Now let's see it in action.
07:34So the first thing now that we got that
07:36is what I really want to do
07:37is I want to change the access level of the folder SSH.
07:41To do that, I want to say this user,
07:43who basically me, has absolute access.
07:47We could read, write, and execute, no problem.
07:50But we don't want to let the group,
07:52any group that has access to this user
07:56or any group that has access to this place,
07:59to this folder, we don't want to give it any access.
08:02And if anyone that is not in the group,
08:05we don't want to give any access as well.
08:07So we're going to put their zero as well.
08:08Basically what we're saying is,
08:10I will have absolute access to this,
08:12no one else will have any access at all.
08:15Okay, now on the other hand,
08:17if I wanted to let everyone access
08:18and do whatever they want with it,
08:19it would be 777, right?
08:22Or if it would be everyone, me and everyone in my group,
08:24it would be 770, okay?
08:27But in this case, I only want to have complete access
08:30and everyone else won't have any access.
08:32And to what folder, what file are we talking about?
08:34We're going to stay in this folder
08:36because we're in our home folder
08:38and I want to access this SSH and say,
08:41hey, this folder only I could access it.
08:43Just make sure only me.
08:44So I'm going to click enter there
08:45and I'm going to define that as a file
08:49that only I could enter, read, write or execute.
08:53Next one, I want to define my actual file itself
08:56and the file itself has no executable.
08:59This is a text file that you could only read from it.
09:02It's not an executable even.
09:04So I want to make sure that this file
09:05has a 600 value, meaning that you could read
09:08and you could write into it,
09:10but you cannot do anything but that.
09:12You cannot execute it.
09:14So again, I'm going to go into my folder itself, SSH,
09:17and I'm going to go into that Authorize Keys
09:19and I'm going to, oh, I had a typo there,
09:22not CMON, true, from R, so it's C mode.
09:27Let me just go right in there and fix that C mode.
09:29And we're going to fix that and there we go.
09:30Now we define the access level to this file.
09:33It should only be write or read, perfect.
09:37We're almost done.
09:38All that's left for us to do to activate this change
09:41is to basically, the step involved right now
09:44at this stage is we want to basically go to the server
09:47and basically tell our server,
09:49hey, the access file from here on
09:51is located inside of our .SSH folder.
09:55It will automatically search for Authorize Keys,
09:57but you want to make sure that it knows
09:59in what folder it is.
10:01So to do that, to make sure that the user,
10:04our system, our sentos knows how to go there.
10:06We're going to write here, resto recon
10:11minus R, lowercase r, lowercase v,
10:15and then we're going to direct the system
10:18into that folder, all right?
10:22And you don't have to understand it.
10:23All it really does is says, hey,
10:25this is where our authorization key is going to be sitting.
10:28So it's restore connection, I guess,
10:31restore con, minus space, minus uppercase R,
10:36lowercase v, into our home folder,
10:39and we're just defining right the path of our folder itself.
10:43And that's all we had to do.
10:44And once we did that,
10:45we defined the location of our restoration.
10:50All that's left for us to do is to test this out.
10:53So I'm going to log out and I'm going to test it out
10:56on a Mac to show you how we're connecting through
10:59with a Mac.
11:00So anyway, if already, you know,
11:02if we're already talking about this,
11:04let me just make sure I have this file here.
11:07Because I'm working both on a Mac and also on a PC,
11:11I might have an issue where I have access
11:14only one access code that's working
11:16because I'm using the same user
11:18and I'm adding that user into that same access code.
11:22If you're adding more than one key,
11:25we talked about this previously
11:26where you could go into that actual folder itself
11:30and then the folder itself, edit that, authorize keys.
11:33Another way is if you're uploading a file onto your server
11:36and we have your new file that's sitting here on the server,
11:39what I could do then is basically copy that file
11:43and using the cat command.
11:45Now we're not going to go into how to do it right now,
11:48but if it's something that you want to know
11:50if you want us to create a video about it,
11:51then add a comment right here and say,
11:53hey, Ben, could you show us, add us this video?
11:56Go out there and do a little search on Google,
11:58search for the command cat
12:00and literally all the process involved is file
12:03and after you do file, the file name itself,
12:07you define the file name itself
12:09and then you put your lesser than lesser than
12:12and where you want it to be and in our case,
12:15we want it to be inside of our .SSH folder
12:18and we want it to be inside of our authorized keys.
12:21That's really the process.
12:23I'm going to take a small pause
12:25and I'm going to get my Mac ready
12:27and I'm going to get my PC ready
12:29and then we're going to just do it together.
12:30So in a second, we're just going to be like
12:36the power of technology.
12:37So we're back again in the Mac side.
12:39If you're a Windows user, still watch this
12:41because we're going to get to you in a second
12:43and this is something that's good
12:44for you to know in general.
12:46So from the Mac side, what I want to do
12:47is I just want to send with a secure copy.
12:49I'm going to send that copy the file again.
12:51The reason is because when we did our video on Windows,
12:55we actually overrode and we deleted our public key
12:58and started over for our Windows users.
13:00So I'm just going to send that file into our server
13:02and I'm going to do that really quick together.
13:04As soon as the file was sent,
13:05I'm going to go back into my demo account,
13:08make sure that the file is there and it sure is.
13:11But this time around,
13:12because we already have our key there,
13:15we don't want to delete our Windows key, heavens forbid.
13:18What we want to do is you want to append
13:20to the end of the file our new key.
13:23So to do that, all we have to do
13:24is we're going to type cat,
13:26which is going to help us copy that file
13:28or push that copy into the end of the file.
13:30We're going to say, what do we want to copy?
13:32We want to copy this file.
13:34Where do we want to copy it to?
13:36We want to copy into the SSH folder,
13:37into the authorized keys
13:39and we want to push it towards the end there.
13:41But in between these two lines where from to two,
13:44we need to tell it, what do we want to do?
13:46So what I want to do is I want to push it to the end of it.
13:49So this is the command for that.
13:50This is the key for that,
13:51which is just lesser than lesser than
13:53and that's going to send it to the end of the file.
13:56And that's it.
13:57Once I click enter, it's going to send in my key.
13:59And now I have two keys there.
14:01And this is exactly the steps.
14:03Hey, windows people promise you
14:04that it's something you'd want to watch.
14:06So it doesn't matter every single computer
14:08where you create a private and public key.
14:10This is the steps you want to take,
14:12you want to send that public key and add it in.
14:15And literally we just cleared our,
14:17we added it in into our authorized keys.
14:20So if I go into, inside of my V
14:22and I try to go into that SSH folder,
14:26let me just go into that folder,
14:31authorized users, authorize underscore keys,
14:35you'll see that now we have two keys, one and two.
14:39All righty, and that's it.
14:40That's basically all we have to do
14:42to double check and validate
14:44that we have access to both our keys.
14:46And I'm just going to exit without saving anything.
14:49So I'm going to click on shift colon, lowercase Q,
14:54and the command or shift one,
14:56press enter there and that's it.
14:59Now in the next video where I'm going to open up windows
15:03and I'm going to open up our Mac
15:04and I'm going to show you how do we log in
15:05without using a user anymore password.
15:08Now that we have our authorized keys set up
15:10and we connected it and it's all set.
15:13So see you in the next video
15:15where that's what we're going to do.
15:16We're going to open up both windows
15:17to see how do you connect from windows.
15:18And we're going to see how do you connect
15:19from a Mac now without a password.
