WEBVTT - This file was automatically generated by VIMEO

0
00:00:07.520 --> 00:00:10.420
In this video, you learn how to harden your S SSH server.

1
00:00:12.050 --> 00:00:16.710
Our plan is to explore how to harden SSH server. Amazon Lennox does a good job,

2
00:00:16.730 --> 00:00:19.990
but we'll review five configuration parameters that you should make sure are

3
00:00:20.010 --> 00:00:20.730
set.

4
00:00:20.730 --> 00:00:25.210
You will test the SSH server changes for any errors and then restart.

5
00:00:26.530 --> 00:00:30.860
Here are the five configuration changes that we're gonna go over in our config

6
00:00:30.860 --> 00:00:33.540
file. Some of these will already be set as the default,

7
00:00:33.540 --> 00:00:35.820
but it's better to be explicit and set them anyway.

8
00:00:36.170 --> 00:00:37.740
Once we are in the configuration file,

9
00:00:37.770 --> 00:00:39.420
I'll go over what each of these actually do.

10
00:00:40.200 --> 00:00:44.780
Permit route login should be set to know password authentication should be set

11
00:00:44.780 --> 00:00:45.613
to know.

12
00:00:46.120 --> 00:00:51.060
Max auth try should be set to three client live interval should be set

13
00:00:51.060 --> 00:00:55.250
to 300 x 1140 should also be set to know.

14
00:00:56.260 --> 00:00:59.980
Okay, let's get started. Okay,

15
00:01:00.280 --> 00:01:04.780
so we're gonna set some explicit configuration settings in our S SSH server.

16
00:01:05.080 --> 00:01:09.780
The configuration file for the SSH server is located under the Etsy directory,

17
00:01:09.990 --> 00:01:12.660
under the Etsy s SSH direct to be explicit.

18
00:01:13.080 --> 00:01:16.860
And our config file is SS h d underscore config.

19
00:01:17.320 --> 00:01:22.060
You will need pseudo access to run any of the ssh uh commands and also to make

20
00:01:22.080 --> 00:01:24.660
any changes to this file or restart the service.

21
00:01:25.120 --> 00:01:28.260
So let's go ahead and open up our config file in your editor.

22
00:01:29.900 --> 00:01:30.970
Don't forget pseudo

23
00:01:34.420 --> 00:01:38.440
and ss h d underscore config. Make sure you get that one.

24
00:01:38.440 --> 00:01:41.900
Cause we want the one for the server. Okay.

25
00:01:43.790 --> 00:01:44.970
So as you can see here,

26
00:01:44.970 --> 00:01:49.770
there's a lot of configuration changes and the format of it is like it'll

27
00:01:49.790 --> 00:01:52.450
be the name of the setting and then the value.

28
00:01:53.280 --> 00:01:57.170
So a lot of these are commented out, not because uh,

29
00:01:57.280 --> 00:02:00.930
they're not in use, but some of these are defaults. Like port 22 is the default,

30
00:02:01.350 --> 00:02:02.850
but they have it here, commented out.

31
00:02:03.060 --> 00:02:06.890
We're gonna ignore all that and we're just gonna go through what we and do what

32
00:02:06.890 --> 00:02:09.390
we think is right. And this way,

33
00:02:09.730 --> 00:02:13.110
if you're ever on a host that is not set up like this, you will know what to do.

34
00:02:14.020 --> 00:02:17.550
Okay, so let's go down to our first one here under the authentication level.

35
00:02:17.930 --> 00:02:21.870
And it says permit root login. So if we set this to yes,

36
00:02:22.050 --> 00:02:24.150
if we uncommon this and we keep it as yes,

37
00:02:24.380 --> 00:02:27.390
that means root can log into our SSH server.

38
00:02:27.770 --> 00:02:31.830
We don't ever want route to be able to log into a host v SSH root account is

39
00:02:31.830 --> 00:02:36.390
very special and uh, we don't want to just be using it for everyday activities.

40
00:02:36.390 --> 00:02:39.710
That is what pseudo is for. If you need some temporary elevated permission.

41
00:02:39.770 --> 00:02:44.550
So we are going to change the permit route Login into

42
00:02:44.570 --> 00:02:47.270
No, we're gonna set it explicitly, no.

43
00:02:49.420 --> 00:02:53.030
Okay. So there is another one that we're gonna go to here,

44
00:02:53.030 --> 00:02:54.470
which is max off price.

45
00:02:54.570 --> 00:02:57.030
I'm gonna just gonna go in a row here as we see them on the screen.

46
00:02:57.260 --> 00:03:00.640
They may not be the exact same. They, they were laid out in the uh,

47
00:03:00.640 --> 00:03:03.160
slide though. So Max Auth tries.

48
00:03:03.220 --> 00:03:07.160
So this sets the max amount of login attempts the server will allow.

49
00:03:07.430 --> 00:03:10.320
This should help cut down some of the brute force attacks we were seeing in the

50
00:03:10.320 --> 00:03:14.170
last video. So we're gonna set that to three. Okay.

51
00:03:14.170 --> 00:03:18.150
And we're gonna keep going down here. Okay,

52
00:03:18.690 --> 00:03:21.670
so this permit empty passwords is no,

53
00:03:21.820 --> 00:03:25.310
sometimes you can create users that with, uh, without a password,

54
00:03:25.890 --> 00:03:29.430
but instead of allowing non empty passwords,

55
00:03:29.430 --> 00:03:33.270
we're just not gonna allow passwords at all. And as you can see on line 62 here,

56
00:03:33.630 --> 00:03:35.590
password authentication is set to know.

57
00:03:35.900 --> 00:03:39.750
This will deny anyone trying to log into the host using their Lennox account

58
00:03:40.150 --> 00:03:44.230
password. This means that everybody who wants to access this host must be using,

59
00:03:44.490 --> 00:03:48.970
uh, your key, a key pair. So it's already set to know. So we'll just leave that,

60
00:03:50.010 --> 00:03:51.430
uh, we'll keep going down here.

61
00:03:55.020 --> 00:03:58.070
Okay, the next one we're gonna talk about here is the X 11 forwarding.

62
00:03:58.290 --> 00:04:01.870
So the X 11 server is a graphical server and it can be used.

63
00:04:02.210 --> 00:04:04.230
One of the neat things it can do is, um,

64
00:04:04.490 --> 00:04:09.350
you can have a graphical application running on one host remotely and on the

65
00:04:09.370 --> 00:04:11.070
client that you're ss from,

66
00:04:11.530 --> 00:04:15.790
you can have it forward or tunnel that application information over to your

67
00:04:15.790 --> 00:04:19.350
screen. So it's like you're actually on that machine, but you're not,

68
00:04:19.350 --> 00:04:24.110
you're using your own, uh, X 11 server. While that is a great feature,

69
00:04:24.620 --> 00:04:28.830
it's not shrouded in security, excuse me,

70
00:04:28.900 --> 00:04:33.790
it's not shrouded in security. So if we don't need it, you should turn it off.

71
00:04:34.290 --> 00:04:34.610
You know,

72
00:04:34.610 --> 00:04:38.790
the least amount of stuff you can do is a great security habit in something you

73
00:04:38.990 --> 00:04:41.030
should always be in, uh, looking forward to.

74
00:04:42.050 --> 00:04:46.070
So we're also gonna come down here and we're gonna say client interval.

75
00:04:47.050 --> 00:04:51.500
Okay? So the client interval is, uh, this will limit the client connection.

76
00:04:51.610 --> 00:04:54.140
Idle state right now, zero means unlimited.

77
00:04:54.160 --> 00:04:56.500
The client connection will just stay alive forever. Basically,

78
00:04:57.040 --> 00:04:59.620
if the client does not respond with a keep alive,

79
00:04:59.640 --> 00:05:02.060
the server will sever the connection, which is what we want.

80
00:05:02.160 --> 00:05:05.580
You don't wanna have a whole bunch of long-lived SSH connections connecting

81
00:05:05.610 --> 00:05:09.260
into, let's say a production host. You leave your laptop, uh,

82
00:05:09.260 --> 00:05:11.900
unlocked or something, somebody comes in, now they have full access.

83
00:05:12.440 --> 00:05:17.220
So we're gonna uncommon that. Remove the pound sign and we're gonna set this.

84
00:05:17.320 --> 00:05:22.140
We go to insert mode with I and Vim and we're gonna set this to 300, which is,

85
00:05:22.140 --> 00:05:23.020
should be five minutes.

86
00:05:28.140 --> 00:05:31.180
Okay? Let's just go down here to the bottom. Uh,

87
00:05:31.180 --> 00:05:33.500
we just wanna make sure we're not missing any. Um,

88
00:05:33.500 --> 00:05:38.190
here's a good example as well. You could do a match, which is really nice.

89
00:05:38.530 --> 00:05:43.230
So if you wanted to match for a specific user that you could disable or

90
00:05:43.230 --> 00:05:44.950
enable settings based on that user.

91
00:05:45.090 --> 00:05:47.470
So like remember when we created the Acui user,

92
00:05:47.930 --> 00:05:49.830
you could do something here that says, uh,

93
00:05:49.830 --> 00:05:54.580
we want a ki to be able to x 11 forward and they could use,

94
00:05:54.680 --> 00:05:57.160
uh, the password, the condition for only for them, them.

95
00:05:57.840 --> 00:06:00.500
But we're not gonna use that here. I just want you to know exist. All right,

96
00:06:00.680 --> 00:06:05.220
so we're gonna shift colon x, we're gonna write and quit out of this file.

97
00:06:05.320 --> 00:06:10.130
We wanna save our changes obviously. So what we're gonna do,

98
00:06:10.130 --> 00:06:13.210
I'm gonna clear the screen and what we're gonna do is we're gonna use pseudo and

99
00:06:13.210 --> 00:06:15.010
we're gonna use the SS h d command.

100
00:06:15.310 --> 00:06:19.370
But what you're gonna use a capital T and what the capital T does is gonna test

101
00:06:19.390 --> 00:06:21.090
our configuration file for errors.

102
00:06:21.470 --> 00:06:25.570
So reason why you want this is a good habit to get into is let's say I made an

103
00:06:25.570 --> 00:06:30.130
error in that configuration file and then I go to restart our S SSH server and

104
00:06:30.130 --> 00:06:34.450
it doesn't come back up. I don't realize it, it doesn't work.

105
00:06:34.450 --> 00:06:38.210
And then now nobody can access it. So it's important to go ahead and run this.

106
00:06:38.350 --> 00:06:41.450
So if you run this, it'll spit out errors and lines, uh,

107
00:06:41.450 --> 00:06:44.410
where it thinks is a problem. If it is not an error,

108
00:06:44.410 --> 00:06:48.010
you'll get the output of basically a summary of all this overall setting.

109
00:06:48.110 --> 00:06:52.590
So let's go ahead and pseudo S S H D minus T here now. Okay,

110
00:06:52.730 --> 00:06:55.350
so as you can see, there was no errors that came out.

111
00:06:55.350 --> 00:06:57.750
I'll scroll over here to the top. Excuse the uh,

112
00:06:57.750 --> 00:07:01.310
fast scroll and we could see here these are all the defaults,

113
00:07:01.310 --> 00:07:03.390
everything that's been using. And let's see,

114
00:07:03.390 --> 00:07:08.190
we could see here max off retry or tries is now three,

115
00:07:08.190 --> 00:07:11.630
which is what we set it to. Client interval is 300,

116
00:07:12.170 --> 00:07:16.510
the client alive count max. Um, what this basically does, it says,

117
00:07:16.940 --> 00:07:18.870
okay, the five minutes is up,

118
00:07:19.010 --> 00:07:23.550
I'm gonna send you a keep alive and I will do that three different times before

119
00:07:23.790 --> 00:07:25.470
I kill the connection.

120
00:07:25.890 --> 00:07:28.110
You could honestly lower that to one if you really wanted to,

121
00:07:28.110 --> 00:07:31.590
or two in case cuz I mean network hiccups do happen, but let's keep going down.

122
00:07:32.090 --> 00:07:35.430
Permit route login is no, which is exactly what we wanted.

123
00:07:36.750 --> 00:07:38.510
X 11 forwarding is no.

124
00:07:42.860 --> 00:07:46.560
All right, so that is all that.

125
00:07:46.560 --> 00:07:49.600
The rest of this you can safe ignore. These are just other commands that,

126
00:07:49.670 --> 00:07:54.310
that were not either set or commented out in the uh, file.

127
00:07:55.010 --> 00:07:59.110
But now, so the next thing we want to do is we wanna restart our s SSH server.

128
00:07:59.210 --> 00:08:01.350
Now, it shouldn't drop your connection. Nothing should happen.

129
00:08:01.730 --> 00:08:03.230
So let me go ahead and clear the screen.

130
00:08:03.980 --> 00:08:08.790
And then I am going to do pseudo system CTL restart SS

131
00:08:09.050 --> 00:08:12.030
HD dot service. I'll go ahead and pause the video here,

132
00:08:12.030 --> 00:08:16.430
cause this might take a second and then I'll be right back. Okay,

133
00:08:16.490 --> 00:08:20.710
so here we are. I restarted it. Um, my connection wasn't severed.

134
00:08:20.930 --> 00:08:25.310
And if we run the SS H D T command, um, I'll scroll back up.

135
00:08:25.490 --> 00:08:30.340
And our settings are now permanent.

136
00:08:30.560 --> 00:08:33.900
So any new connections coming in, we'll have to obey by these rules.

137
00:08:36.110 --> 00:08:40.930
All right, so there we are with the five quick, easy, uh, hardening tips.

138
00:08:41.430 --> 00:08:46.370
Um, let's jump back over and let's do a full recap. Okay,

139
00:08:46.370 --> 00:08:48.450
so let's talk about what we did. In this video,

140
00:08:48.990 --> 00:08:51.650
you learn how to harden an s SSH server on Lennox.

141
00:08:52.030 --> 00:08:55.760
You explicitly set five parameters like password authentication,

142
00:08:55.760 --> 00:09:00.440
permit route login, and X 11 forwarding. To improve our SSH security posture,

143
00:09:01.250 --> 00:09:05.150
you applied changes and tested the configuration file for any errors using the

144
00:09:05.270 --> 00:09:08.230
SS h d command. Well,

145
00:09:08.400 --> 00:09:11.270
we've reached the end of section six, Lennox Security.

146
00:09:11.810 --> 00:09:15.830
In this section you gotta crash course in authentication and Lennox security.

147
00:09:16.130 --> 00:09:20.470
You learn how to monitor your host for specific security events and search logs

148
00:09:20.470 --> 00:09:22.660
for bad actors. In the next section,

149
00:09:22.760 --> 00:09:26.500
you will learn some more common Lennox and AW S commands that you can apply to

150
00:09:26.500 --> 00:09:28.380
your everyday job. See you soon.
