1
1

00:00:00,230  -->  00:00:02,020
<v Instructor>Hi, guys, and welcome back.</v>
2

2

00:00:02,020  -->  00:00:03,770
In this video, we're going to be adding a little bit
3

3

00:00:03,770  -->  00:00:05,542
of configuration to our new user
4

4

00:00:05,542  -->  00:00:08,300
so that it has the power that it needs
5

5

00:00:08,300  -->  00:00:09,660
to do certain actions
6

6

00:00:09,660  -->  00:00:12,223
and also so that it can log into the server.
7

7

00:00:13,437  -->  00:00:16,035
At the moment, we are the root user,
8

8

00:00:16,035  -->  00:00:17,899
which we mentioned in the last video
9

9

00:00:17,899  -->  00:00:21,070
is the administrator user of the system.
10

10

00:00:21,070  -->  00:00:22,300
It's a little bit dangerous
11

11

00:00:22,300  -->  00:00:25,110
to be the administrator user at all times
12

12

00:00:25,110  -->  00:00:26,927
because it gives you a bit too much power
13

13

00:00:26,927  -->  00:00:31,040
to do things that maybe you make by accident.
14

14

00:00:31,040  -->  00:00:33,770
However, the new user,
15

15

00:00:33,770  -->  00:00:35,220
Jose in our case,
16

16

00:00:35,220  -->  00:00:39,390
should have the ability to be the administrator user
17

17

00:00:39,390  -->  00:00:40,880
to perform certain actions
18

18

00:00:40,880  -->  00:00:43,140
if it really needs to.
19

19

00:00:43,140  -->  00:00:44,690
We're gonna do that so that,
20

20

00:00:44,690  -->  00:00:46,672
for example, if we want to instal a new programme
21

21

00:00:46,672  -->  00:00:48,980
in the server or something like that,
22

22

00:00:48,980  -->  00:00:52,310
we don't have to log out and log back in as the root user.
23

23

00:00:52,310  -->  00:00:55,930
We can just do it as our Jose user.
24

24

00:00:55,930  -->  00:00:58,920
Now, of course, whenever you allow any user
25

25

00:00:58,920  -->  00:01:01,207
to temporarily become the root user,
26

26

00:01:01,207  -->  00:01:04,170
that can be dangerous too.
27

27

00:01:04,170  -->  00:01:07,500
So do be careful about when you become the root user
28

28

00:01:07,500  -->  00:01:08,473
and when you don't.
29

29

00:01:09,750  -->  00:01:11,841
In order to do this,
30

30

00:01:11,841  -->  00:01:13,960
we need to type visudo,
31

31

00:01:13,960  -->  00:01:16,220
all one letter, and then press enter.
32

32

00:01:16,220  -->  00:01:20,010
Here, we're going to be finding this line down here
33

33

00:01:20,010  -->  00:01:24,640
that says root ALL = ALL:ALL,
34

34

00:01:24,640  -->  00:01:28,220
very nice and descriptive line right there.
35

35

00:01:28,220  -->  00:01:31,533
And we're actually gonna say that the Jose user
36

36

00:01:31,533  -->  00:01:34,543
will also have all of the privileges.
37

37

00:01:35,960  -->  00:01:37,240
So, all you have to do is,
38

38

00:01:37,240  -->  00:01:38,073
underneath that line,
39

39

00:01:38,073  -->  00:01:43,073
type Jose ALL = ALL ALL ALL.
40

40

00:01:43,088  -->  00:01:44,890
Just like that.
41

41

00:01:44,890  -->  00:01:46,560
The spacing doesn't matter much,
42

42

00:01:46,560  -->  00:01:49,980
but you do need to have at least one space after Jose
43

43

00:01:49,980  -->  00:01:53,030
and one space after these brackets.
44

44

00:01:53,030  -->  00:01:57,090
And of course, remember, all the ALLs have to be uppercase.
45

45

00:01:57,090  -->  00:01:58,800
Now that we have done this,
46

46

00:01:58,800  -->  00:02:01,160
you can refer to the instructions down here at the bottom
47

47

00:02:01,160  -->  00:02:04,860
to save and exit this file that you have open.
48

48

00:02:04,860  -->  00:02:06,950 line:15% 
So in order to save the file,
49

49

00:02:06,950  -->  00:02:09,540 line:15% 
we're gonna type Control + O
50

50

00:02:11,460  -->  00:02:13,210 line:15% 
and then press enter.
51

51

00:02:13,210  -->  00:02:16,600 line:15% 
And then to exit, we're gonna type Control + X.
52

52

00:02:16,600  -->  00:02:18,630 line:15% 
And that's everything you have to do.
53

53

00:02:18,630  -->  00:02:21,120
Now we're gonna allow our user to log in,
54

54

00:02:21,120  -->  00:02:24,080
because by default this user that we've created,
55

55

00:02:24,080  -->  00:02:26,770
the user Jose, cannot log into the server.
56

56

00:02:26,770  -->  00:02:29,050
That's because we want to prevent users
57

57

00:02:29,050  -->  00:02:32,650
from logging into the server by default for security.
58

58

00:02:32,650  -->  00:02:34,190
So if you want to allow the user,
59

59

00:02:34,190  -->  00:02:36,580
you have to explicitly say so.
60

60

00:02:36,580  -->  00:02:41,580
We're gonna type vi/etc/ssh/sshd_config.
61

61

00:02:44,641  -->  00:02:45,474
Okay?
62

62

00:02:45,474  -->  00:02:48,352
And then, we're gonna go and scroll through
63

63

00:02:48,352  -->  00:02:50,689
this file using the arrow keys
64

64

00:02:50,689  -->  00:02:52,720
until you come across this line called
65

65

00:02:52,720  -->  00:02:56,390
PasswordAuthentication yes.
66

66

00:02:56,390  -->  00:02:59,010
Make sure that it does equal yes.
67

67

00:02:59,010  -->  00:03:01,800
For example, if you use an ssh key to log into the server,
68

68

00:03:01,800  -->  00:03:04,920
you're gonna have to change this from no to yes.
69

69

00:03:04,920  -->  00:03:06,490
If you are using a password,
70

70

00:03:06,490  -->  00:03:07,830
you won't have to make any changes.
71

71

00:03:07,830  -->  00:03:08,663
Of course, evidently,
72

72

00:03:08,663  -->  00:03:10,250
you've already logged in using a password,
73

73

00:03:10,250  -->  00:03:12,440
so you don't have to allow it again.
74

74

00:03:12,440  -->  00:03:15,317
Next, we're gonna find PermitRootLogin,
75

75

00:03:16,160  -->  00:03:20,420
and instead of just scrolling through with the arrow keys,
76

76

00:03:20,420  -->  00:03:22,200
which you can do,
77

77

00:03:22,200  -->  00:03:24,480
you can also type a question mark,
78

78

00:03:24,480  -->  00:03:27,060
and then you'll see it appear down here.
79

79

00:03:27,060  -->  00:03:30,373
And you can type PermitRootLogin.
80

80

00:03:31,330  -->  00:03:33,470
Make sure that capitalization is correct.
81

81

00:03:33,470  -->  00:03:34,620
And then you can press enter,
82

82

00:03:34,620  -->  00:03:36,870
and it will find where it happens,
83

83

00:03:36,870  -->  00:03:38,570
and you can just type question mark again,
84

84

00:03:38,570  -->  00:03:40,460
and it will find every instance
85

85

00:03:40,460  -->  00:03:43,440
of PermitRootLogin that it can.
86

86

00:03:43,440  -->  00:03:46,088
So, once you've found PermitRootLogin yes,
87

87

00:03:46,088  -->  00:03:48,730
just make sure to use the arrow keys
88

88

00:03:48,730  -->  00:03:50,680
to scroll to the end of the line.
89

89

00:03:50,680  -->  00:03:54,873 line:15% 
Then press the I key to go into insert mode.
90

90

00:03:55,720  -->  00:03:57,063 line:15% 
And change this to no.
91

91

00:03:57,910  -->  00:03:59,930 line:15% 
Then press the Escape key.
92

92

00:03:59,930  -->  00:04:03,460 line:15% 
And then press : W.
93

93

00:04:03,460  -->  00:04:05,850 line:15% 
That is going to save your files.
94

94

00:04:05,850  -->  00:04:09,180
So now we have disallowed the root user
95

95

00:04:09,180  -->  00:04:10,780
from logging into our server.
96

96

00:04:10,780  -->  00:04:12,160
So why do we do this?
97

97

00:04:12,160  -->  00:04:13,860
Again, for security.
98

98

00:04:13,860  -->  00:04:16,248
If the root user who is the administrator of our server
99

99

00:04:16,248  -->  00:04:18,112
cannot directly log in,
100

100

00:04:18,112  -->  00:04:21,064
that means that any attacker who finds the root password
101

101

00:04:21,064  -->  00:04:24,600
won't be able to exploit it all that easily.
102

102

00:04:24,600  -->  00:04:28,500
Next, we have to allow our new user to log in.
103

103

00:04:28,500  -->  00:04:29,790
So what I'm gonna do is I'm gonna go down
104

104

00:04:29,790  -->  00:04:31,333
to the very end of this file.
105

105

00:04:34,720  -->  00:04:36,520
Go to the end of the line.
106

106

00:04:36,520  -->  00:04:38,900
Then press the I key
107

107

00:04:38,900  -->  00:04:42,610
and type AllowUsers jose.
108

108

00:04:42,610  -->  00:04:45,650
Now, here you may already have other users.
109

109

00:04:45,650  -->  00:04:47,430
For example, if you're using AWS,
110

110

00:04:47,430  -->  00:04:49,970
you'll have an ubuntu user here as well.
111

111

00:04:49,970  -->  00:04:52,470
Just have your users separated by spaces
112

112

00:04:52,470  -->  00:04:55,130
if you want to allow more than one, okay?
113

113

00:04:55,130  -->  00:04:57,690
But for now, we just have the Jose user,
114

114

00:04:57,690  -->  00:04:59,530
so we don't need to add anything else.
115

115

00:04:59,530  -->  00:05:00,960
We're gonna press Escape once again.
116

116

00:05:00,960  -->  00:05:03,730 line:15% 
We're gonna press : W
117

117

00:05:03,730  -->  00:05:06,510 line:15% 
to write this and save it to the disc,
118

118

00:05:06,510  -->  00:05:10,060 line:15% 
and then we're gonna type : Q to quit,
119

119

00:05:10,060  -->  00:05:11,623 line:15% 
exit the current file.
120

120

00:05:12,860  -->  00:05:14,340
Now that we've done that,
121

121

00:05:14,340  -->  00:05:17,900
we're gonna do service sshd reload.
122

122

00:05:17,900  -->  00:05:21,390
But now a problem can happen when you do this,
123

123

00:05:21,390  -->  00:05:23,798
which is, if you make a mistake in allowing your user
124

124

00:05:23,798  -->  00:05:25,740
and you prevent the root user,
125

125

00:05:25,740  -->  00:05:27,650
that means there are no further users
126

126

00:05:27,650  -->  00:05:28,830
that you can log in with.
127

127

00:05:28,830  -->  00:05:32,980
However, using the DigitalOcean website's console
128

128

00:05:32,980  -->  00:05:35,180
that you can see on your droplet,
129

129

00:05:35,180  -->  00:05:37,142
you can still log in even if
130

130

00:05:37,142  -->  00:05:40,030
you don't have the root user allowed.
131

131

00:05:40,030  -->  00:05:41,860
So if that happens,
132

132

00:05:41,860  -->  00:05:44,420
you can go to DigitalOcean and log in
133

133

00:05:44,420  -->  00:05:47,920
through the browser console there
134

134

00:05:47,920  -->  00:05:50,513
and change this file again to fix
135

135

00:05:50,513  -->  00:05:52,673
whatever problem you may have made.
136

136

00:05:54,070  -->  00:05:56,790
But if not, then you can just do that,
137

137

00:05:56,790  -->  00:05:59,650
and now you can no longer log in as root.
138

138

00:05:59,650  -->  00:06:01,440
But we are logged in as root for now,
139

139

00:06:01,440  -->  00:06:03,383
so we won't be kicked out.
140

140

00:06:04,690  -->  00:06:06,930
However, once we do log out,
141

141

00:06:06,930  -->  00:06:11,930
that you can do by pressing Control + D or just logout.
142

142

00:06:12,090  -->  00:06:14,410
You can type just logout or you can press Control + D
143

143

00:06:14,410  -->  00:06:16,450
if you're on Linux or Mac.
144

144

00:06:16,450  -->  00:06:17,990
Then you will be logged out,
145

145

00:06:17,990  -->  00:06:19,750
and now you have to log back in.
146

146

00:06:19,750  -->  00:06:23,540
So to log back in, just type ssh.
147

147

00:06:23,540  -->  00:06:28,083
And now I'm gonna go for Jose at my server.
148

148

00:06:29,580  -->  00:06:33,240
It asks me for the password, which is a good sign.
149

149

00:06:33,240  -->  00:06:34,763
We type it in.
150

150

00:06:35,620  -->  00:06:39,173
And there we have our user already logged in.
151

151

00:06:39,173  -->  00:06:40,633
No problem at all.
152

152

00:06:42,900  -->  00:06:44,320
Now that we've got this,
153

153

00:06:44,320  -->  00:06:46,620
we have to do one final thing,
154

154

00:06:46,620  -->  00:06:47,860
and that's gonna allow us to use
155

155

00:06:47,860  -->  00:06:51,710
this temporary root user that I was mentioning earlier,
156

156

00:06:51,710  -->  00:06:53,520
which is, we're gonna update our system.
157

157

00:06:53,520  -->  00:06:55,330
We're gonna update the operating system here.
158

158

00:06:55,330  -->  00:06:57,300
And the way we're gonna do that is
159

159

00:06:57,300  -->  00:07:01,733
by doing sudo apt-get update.
160

160

00:07:02,630  -->  00:07:05,360
When you do sudo anything,
161

161

00:07:05,360  -->  00:07:08,630
this command, apt-get update,
162

162

00:07:08,630  -->  00:07:12,400
will be executed as if you were the root user.
163

163

00:07:12,400  -->  00:07:14,880
So temporarily it logs you in as the root user,
164

164

00:07:14,880  -->  00:07:17,240
executes the command, and then it logs you out.
165

165

00:07:17,240  -->  00:07:20,560
Apt-get update is going to update all of the packages
166

166

00:07:20,560  -->  00:07:21,890
that are installed in your system
167

167

00:07:21,890  -->  00:07:23,280
to the latest version,
168

168

00:07:23,280  -->  00:07:26,217
so that can be quite a handy thing.
169

169

00:07:26,217  -->  00:07:28,016
And the password that you need to put in here
170

170

00:07:28,016  -->  00:07:31,640
is your password for the Jose user,
171

171

00:07:31,640  -->  00:07:33,700
or the new user you've created.
172

172

00:07:33,700  -->  00:07:34,580
So just type that in,
173

173

00:07:34,580  -->  00:07:37,570
and it will go and update these packages.
174

174

00:07:37,570  -->  00:07:38,540
There shouldn't be too many,
175

175

00:07:38,540  -->  00:07:41,256
just because this is a fresh instal.
176

176

00:07:41,256  -->  00:07:43,330
So that's about it.
177

177

00:07:43,330  -->  00:07:44,410
That's it, finished there.
178

178

00:07:44,410  -->  00:07:45,840
Very rapid.
179

179

00:07:45,840  -->  00:07:46,840
That's it for this video.
180

180

00:07:46,840  -->  00:07:48,650
We have created our user.
181

181

00:07:48,650  -->  00:07:50,020
We have given it permissions.
182

182

00:07:50,020  -->  00:07:51,500
We have updated the system.
183

183

00:07:51,500  -->  00:07:55,096
Now we're ready to add the final packages, like MongoDB,
184

184

00:07:55,096  -->  00:07:59,536
and then instal our application into the server.
185

185

00:07:59,536  -->  00:08:01,283
I'll see you in the next video.
