5 Security tips you want to enforce
This is my 5 tips to help protect your server from attacks.
Video Transcript
00:00So in the next few lessons we're going to talk all about security and improving the chance that
00:06no one will log into your account without you wanting them to do it. Obviously that would be
00:10horrible. So what we're going to do we want to make sure that our basic configurations of our
00:16access control which lets users connect our our device are the least obvious for users.
00:23So let's start with the most basic thing. One is you really want to have a good password
00:28and a good password especially now that you're working with keys and you're not typing a password
00:34on a daily basis if you still need to have a password control make it 20 characters long
00:39have a lot of uppercase and lowercase letters have a lot of non-descript characters such as the
00:45dollar sign and and anything that's not um anything that's not very easy to to to configure
00:53all right um now i want to go through a few stuff so i'm going to trust you guys you're going
00:58to put a very complicated password on your password now what if you know you're the only
01:04person that's going to log in you already set yourself to three keys and you want to make
01:09sure that no one could access that no one could access without a key because if they didn't set
01:14up a key if you didn't set them up a key you already backed up the key as well so you know
01:17that you're saved more or less with that key if you protected it and saved it in a good place
01:22so let's see what we could do so what i want to do is i'm going to use the sudo command
01:27because i want to access the file through the root access i'm going to go with v because i want
01:31to go into the editor and i'm going to go into the folder x um the root folder etc and then
01:38ssh and then sshd config oh ssh going on sshd not sshd there there we go config all right so once
01:54we go in there again i'm going to need to put a password in here to protect me from uh making a
01:59change that i wouldn't want just by the way you still need the password but you don't log in with
02:03the password anymore which is absolutely lovely so let's talk about the first thing and the first
02:09thing i want to talk about is your port id now by default your access port is 22 now hackers on
02:16the web for the most part are not very um especially if your site is not something that
02:22they were specifically targeting when they're fishing for sites to hack and if they want to
02:26hack try to figure out a way to hack in they're going to probably do a few things one they're
02:31going to search for servers that have a have a port of 22 because that's the default port for ssh
02:37for that remote access now if you change that default port to something completely different
02:42then you're lowering the chance that they'll even discover you another thing is once they
02:47find your port they'll probably try to log in with a user that is common so have a complicated
02:52username don't use a username that is is intuitive or that there's a lot of those usernames out there
02:59obviously one of the reasons why we don't want to use the root is because the root itself
03:04every computer has so we definitely want to disable that root user as well
03:09another thing that we might want to do is if we have a lot of users we might want to say hey
03:13only these users could remote access so for example our demo account has remote access we
03:19wanted to have remote access because we're going to be remotely connecting to our computer through it
03:24but as your application has a lot of different users not all of them need remote access
03:29your your server your https doesn't need a remote access so really by limiting who could
03:35access it you could just list out the users that have access and again reducing the possibility
03:40that a hacker will discover a username that's real and then try to log in for example there's
03:45a lot of default application default usernames for a lot of applications some applications when
03:51they're installed have a user of their own and if a hacker is trying to log into your computer they
03:56might search for that user and see if he has remote access so limiting and saying hey only user
04:01one two and three could remotely access that's a fantastic way to protect your system now another
04:07thing that we want to talk about is about we were talking about the protocols of when we were
04:12creating our key we created a protocol and we said there's protocol one there's protocol two
04:16we want to make sure that no user has a protocol one and we're not even validating to protocol
04:21one making sure that we again we have a reduction of risk on our system we're only using the better
04:26security mode okay so what we talked about we talked about maybe we want to disable passwords
04:34altogether maybe we're only going to use a key a key to gain access to our server maybe we'll say
04:40we don't want the root to have access to have to be enabled at all so we don't want the root to be
04:45able to log in at all another option is we might want to say hey we also want to say only these
04:50users could log in and no one but these users we want to also say let's define the protocol
04:56to protocol two and we wanted to find an ip address that's a little bit different something
05:01that users won't define so let's start off and start getting that set so i'm going to find that
05:05port and i'm going to click on a so i could get into insert mode and in the port itself what i
05:10want to do is i want to put a value that's high um and irregular so i wouldn't want to put it
05:15if my default was 22 i'm not going to put 2000 and 22 because it's too intuitive nor am
05:21i going to put any round numbers like a thousand or two thousand nor could i put anything of a
05:26service some there are there are ip's that are reserved to some services but uh all in all if
05:31we'll put here something completely random that's high let's say something above a thousand even
05:35above um something a value that's above a thousand so you'll put here a thousand
05:39eighty two you know something that's not very intuitive or you could get a thousand seven
05:43hundred and eighty two which sounds like a year so it might not be even that great so how about
05:48we uh do it twelve hundred and eighty two so it's a value that doesn't make any sense it doesn't
05:54it's not logical in any means or way so that's one way for us to make sure that we're setting
05:59a port and we're going to see how do we log in because we won't be able to log in with just
06:03by logging in anymore because our default port of 22 won't be active once we set this up so we're
06:08just going to remember this and i'm just going to write in the side so i don't forget the port id
06:12we're going to set the port id id to be 1282 and once we set our port id to 1282 let's continue
06:18and do a few more edits and one i already see that i have the protocol and by the way if
06:22you can't find one of the one of the tags here then just create it it's fine but just make sure
06:28that you go through and search for it first so you don't have it written twice and we don't want to
06:33activate one if we we just want two so i'm i see here that it's written protocol two it's not written
06:37one one and two we're making sure that only uh only two is configured and that that is perfect
06:43that's exactly what we want it to be all right so let's move on to the next one let's search
06:47for allow users let's see if allow users is here at all authentication let's search for uh
06:55let's see i'm looking for allow users and if we have written allow users uh uh uh
07:03let me see just search search search so we're just basically what you guys are going to do as
07:12well so one is i don't see allow users so what i'm going to do is i'm just going to double check
07:17and see if allow users is here um it's not i can't see it anywhere i don't see it here i don't see it
07:25here so let's how about we go here and we will add right underneath the password if we want to allow
07:33users to um authenticate so our who do we want to let authenticate so we're basically we're saying
07:41who do we want to be able to access our server so i'm just going to write here allow and by the
07:46way it could have been in any line really users that's what we want to set the command allow users
07:52and what users you want to let in we want to let the user demo come into this account okay we're
07:58going to just press here and enter so that's we said only demo now if we had other users and we
08:02had another users and you have a couple users that you want to let log in then you just put
08:06your a space and and right here the um user name two uh user name two and so on and so forth you
08:12just put a space and list out the users that you want to give them remote access to your your ssh
08:19okay so that's how we define and add allow users i'm just going to leave demo because that's the
08:24only account here next what i want to talk about is do we want to permit users to authenticate with
08:32a password so you see your password authentication yes i'm going to go right here to password
08:36authentication yes i'm going to set it as no now by the way i've been like assuming that you
08:41guys realize this but i'm just going to say it out loud anyways you see here this um this uh shift
08:47three this um number sign um that means it's commented out you could always delete and
08:53uncomment it so if for example you've done here saying that you don't like you could always come in
08:57and comment it out and say okay i'm not going to do this right now okay but what i'm doing here
09:01is i'm saying hey if there is no key do not authenticate at all just don't work deny access
09:08don't ask for a password as well at all okay so once if we set that that means there will be no
09:14more users that are able to log into our account with passwords meaning there's a much lesser
09:19probability of someone hacking onto our system because they have to have the key and if they
09:23don't have the key there's just no way to access okay so that's a fantastic option now last but not
09:28least what i want to do is i want to disable the root from being able to enter so i'm just
09:33going to search here for the command um permit root login so i'm just going to go all the way to
09:38the top here for a second and just scan through really quickly and what i want to search for is
09:44permit um permit root login and if i can't find permit root login then we're going to create it
09:51ourselves so you see here is permit root login which is right up here so i'm going to delete
09:57that and i'm instead of saying yes i'm going to say no we don't want the root to be able to
10:02log in and that's a really that's really something you want to do because when you're
10:06saying you don't want the root to log in you're basically saying that this user name that users
10:11usually try to attack doesn't exist anymore for the outer world there's no ssh way to get into the
10:16root now if you're asking yourself well but what if i need to get into the root you would be able
10:21to get into the root after you log in as a super user such as the demo and then asking to become
10:27root from within and we'll see how to do that in a video short in a short video from now okay so
10:33i'm going to say permit uh login as no um and that's all that i wanted to do so let me just walk
10:38through the steps so one is permit root login no we're basically saying there's no more root
10:43wait the root cannot log into that account anymore fantastic we also changed a few other
10:50things so let's find what we changed as well we added also password authentication and we said no
10:55in other words we're saying we don't want to have a password authentication anymore if we wanted to
10:59we would set it to be yes disabling it basically says that there is no way to log in if you don't
11:06have a key next we also set the allow users basically making sure that only users that are
11:12permitted will be able to log in last but not least oh we there was two more things right
11:20there are two more things we we went up um in our ports and we changed our port all the way above
11:26here i believe it was on the top somewhere we changed our port to be something non-standard
11:30the default is 22 we changed it to something non-standard as 1282 but something come up with
11:36something completely random and we also made sure that our protocol is protocol 2 so we basically
11:42changed your five things and all the stuff that we're going to change in this file all that's
11:46left for us to do is to save it so i'm going to click on escape and i'm going to click on shifts easy
11:52and now that i save that it's time for me to actually restart the restart the ssh basically
11:57saying to that service restart yourself and update with these new configurations once i do that
12:03that's it if we lost all our our keys we're gone there's no way for us to access our service
12:08anymore so what i want to do right now is i'm gonna i'm gonna um restart the service because
12:14i am ready for this and i'm going to click on service um sshd and we're going to restart it
12:24so i'm i type service the name of the service which this is the service that we're working on
12:28is called sshd on sentos and restart once i do that it's going to say permission denied because
12:34we are user demo right so we have to go here back again and in the beginning of it i'm going
12:40to write here sudo because we want to do it as the root so sudo service sshd restart we're going
12:46to try this one more time and i'm going to type a password to make sure that we're agreed and here
12:51we go we're stopping and starting our sshd all right that's all we have to do from setting up
12:57our system on this end i'm going to pause the video and then we're going to see how to do it
13:02on a mac and how to do it how to log in from now on on a mac and how to log in on a pc
13:08all righty and don't forget once you did this that's it you have to make sure that you have
13:14everything configured and you have all your keys and you're tested out and make sure that everything
13:18is working i would even say if you have another computer just make sure that you could log in from
13:22that other computer after you restart it because you could always undo this as long as you're still
13:26logged in but once you said you you could buy mistakes that it's a way that you can't even
13:31access it and you'll be in trouble if you do that such as if you had a typo on the username
13:36that has access all righty so just make sure that all the configurations were right written correctly
13:42restart it i would even leave it open your your terminal open up another one from another
13:47computer and try to log in again without um with after that restart happens seeing that
13:53everything works then you could close down and you're happy all right so in the next
13:56video we'll see how you log in
